tag:blogger.com,1999:blog-16688108025059613142024-03-14T07:10:22.151-07:00Loda's Blog (hlchou@gmail.com)Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.comBlogger54125tag:blogger.com,1999:blog-1668810802505961314.post-10103554805152222752017-06-04T10:24:00.000-07:002017-06-04T10:24:00.455-07:00ARMv8 與 Linux的新手筆記<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
ARMv8 與 Linux的新手筆記</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>ARMv8 與 Linux的新手筆記</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
by loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
hlchou@gmail.com</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從iPhone 5S採用ARMv8處理器架構後,對於ARMv8 64bits的相關討論很多,也受到大家關注,Google也如預期在2014年底前推出了Android Lollipop (也就是Android 5.0) 操作環境.(官方網站<a href="http://www.android.com/versions/lollipop-5-0/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.android.com/versions/lollipop-5-0/</a> ) ,這也是目前第一個同時支援32bits與64bits執行環境的Android操作環境,而面對新的ARMv8 64bits技術,目前主要還是以ARM本身所公布的技術資料為主,筆者也會基於ARM與Google Android正是公開的技術資料為主,來跟大家介紹ARMv8相關的軟體開發技術,並會佐以Linux Kernel Source Code做對照,讓大家除了知道技術名詞外,也可以實際的在代碼上有所掌握,,期待這能對產業軟體開發者有一點點幫助.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先,讓我們簡單的回顧一下ARM處理器的歷史,簡單的區分, 像是ARMv5核心架構主要用於ARM9處理器系列,而ARMv6的核心架構,則用於ARM11系列產品,雖然前述處理器架構都是32bits的指令,但為了更節省記憶體的需求,ARM也推出了16bits Thumb指令,用以在記憶體受限的環境下,可以在些微影響效能的前提,達到兩者的平衡,隨後又延伸這個需求,提供 16/32bits 效率更高的Thumb2指令集架構. 再來就是,近期智慧型手機最主流的Cortex-A系列處理器,則採用的是32bits ARMv7的處理器架構技術,而在導入64bits ARMv8架構前,也開始有一些更大記憶體需求的產品應運而生,ARM提供給32bits架構不超過4GB記憶體限制的解決方案就是LPAE(Large Physical Address Extension)技術,用以支援最大40bit的實體記憶體定址範圍,然在這機制下,每個Process所見的記憶體空間仍受限於32bits 4GB定址.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文所主要討論的ARMv8架構,同時支援了 32bits 與 64bits兩個模式,並在32bits模式下,也向後相容之前ARMv7架構32bits的軟體產品,藉此可提供目前現有ARM 32bits架構的產品一個平順過渡到ARMv8 32/64bits架構的無縫接軌. ARM並支援在ARMv8 64bits的產品上,同時執行32bits的既有軟體模塊與針對最新64bits軟體架構所設計的軟件,兩個不同指令集與記憶體框架的行程可以同時執行,並透過系統提供的IPC(Inter-Process Communication) 進行協同工作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考ARM網頁(<a href="http://www.arm.com/zh/products/processors/cortex-a/cortex-a53-processor.php" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.arm.com/zh/products/processors/cortex-a/cortex-a53-processor.php</a> ),目前已知對外公開的ARMv8架構包含了Cortex A53與A57,這兩者可用於配搭 big.LITTLE的架構,或可單獨採用.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivhGYOhdFbLuejDQTsZsL75oeehciyGMhyH08uetqQ6imZ8F_rdtxVHkC8N-BO4D_bniyh3L9ZwTNknLAd3GAl-PTilZhBAWnoYaDRpzV6mz9lH1-uMcwBnGyQTBdO_porSpkCsPYlad4/s1600/image001%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="226" data-original-width="578" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivhGYOhdFbLuejDQTsZsL75oeehciyGMhyH08uetqQ6imZ8F_rdtxVHkC8N-BO4D_bniyh3L9ZwTNknLAd3GAl-PTilZhBAWnoYaDRpzV6mz9lH1-uMcwBnGyQTBdO_porSpkCsPYlad4/s1600/image001%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>如下表,為大家常見的ARMv7與ARMv8處理器的簡要比較,供參考.</strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 722px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105"><strong>CPU</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="125"><strong>Core Version</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><strong>Pipeline</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115"><strong>DMIPS/MHz</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="218"><strong>Physical Memory Addresses</strong></td></tr>
<tr class="over"><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105">Cortex A7</td><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="125">ARMv7</td><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158">In-Order</td><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115">1.9</td><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="218">LPAE 40bits</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105">Cortex A15</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="125">ARMv7</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158">Out-of-Order</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115">3.5</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="218">LPAE 40bits</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105">Cortex A53</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="125">ARMv8</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158">In-Order</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115">2.3</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="218">40bits</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105">Cortex A57</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="125">ARMv8</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158">Out-of-Order</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115">4.1</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="218">44bits</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於本文會有不少ARMv8 與 32/64bits相關技術名詞引用,為了便於訊息的一致性,筆者在此先定義如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 850px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>Items</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="763"><strong>Explain</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87">AArch64</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="763">指基於64bits運作的ARMv8 Architecture.( General Purpose Registers X0-X30)</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87">AArch32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="763">指基於32bits運作的ARMv8 Architecture.並且相容於原本的ARMv7 Architecture. (General Purpose RegistersR0-R15)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87">A64</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="763">指在AArch64模式下支援的 ARM 64bits 指令集.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87">A32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="763">指ARMv7架構下支援的 ARM 32bits 指令集,在ARMv8中也有新加入的A32指令集.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87">T32</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="763">指ARMv7架構下支援的 Thumb2 16/32bits指定集,在ARMv8中也有新加入的T32指令集.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文所引用的軟體代碼,會以筆者撰寫本文時參考的Linux Kernel 3.16.3 為基礎,線上瀏覽的Source Code網址可以參考 <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/</a> .最後,撰寫時雖盡力確保資料無誤,若仍有所疏失還請多加包含.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>ARMv8</strong><strong>的基礎認識</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前的理解,談到ARMv8最多人引用的圖會是ARM網站(http://www.arm.com/zh/products/processors/instruction-set-architectures/index.php)所提供如下的架構示意圖(<a href="http://www.arm.com/zh/images/roadmap/V5_to_V8_Architecture.jpg" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.arm.com/zh/images/roadmap/V5_to_V8_Architecture.jpg</a>). 簡要來說, ARMv8的架構沿襲以往ARMv7 與之前處理器技術的基礎,除了有既有16/32bits Thumb2指令的支援外,也向前相容現有的ARM 32bits指令集. 基於64bits的AArch64架構,除了新增A64 (ARM 64bits)指令外,也擴充現有的A32 (ARM 32bits) 與T32 (Thumb2 32bits)指令編碼可在ARMv8 AArch32架構中執行,因此若有特別針對ARMv8 32bits指令集新增指令所撰寫的程式碼(例如: 32bits Crypto),這類程式將只能在ARMv8或之後新的處理器架構上執行,而無法向前相容於ARMv8之前的32bits實體處理器執行上.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCcGGLdcDa1mNJJ12yqzKsJ0Wt3K6zGZTCyLwqt20UNI6_kcR-fhC-G6NI7o0SbGLya3lKwgv2GinB_5QvgnALMCnTK1pfKtNpp35fh_MCF78yXSZiLXKrSvut-VVPABqZB0KR_PplFIo/s1600/image002%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="468" data-original-width="688" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCcGGLdcDa1mNJJ12yqzKsJ0Wt3K6zGZTCyLwqt20UNI6_kcR-fhC-G6NI7o0SbGLya3lKwgv2GinB_5QvgnALMCnTK1pfKtNpp35fh_MCF78yXSZiLXKrSvut-VVPABqZB0KR_PplFIo/s1600/image002%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
AArch64 表示為支援64bits Execution State,而AArch32則是支援 ARMv8之前的32bits Execution State,並有因應AArch64新增額外的能力,確保相容於ARMv7-A的架構. AArch32/64也都支援SIMD (Single-Instruction Multiple-Data)與Floating-Point指令,其中的差異是,AArch32的SIND/Floating-Point使用64bits的暫存器,而AArch64使用的是128bits暫存器.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考文件 Procedure Call Standard for the ARMR Architecture(<a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf</a> ) 與 Procedure Call Standard for the ARM 64-bit Architecture(AArch64) (<a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf</a>),其中有關General purpose registers and AAPCS64 usage段落有針對這31個General Purpose 64bits暫存器的使用方式,可知64bits提供的額外暫存器,包括在Function Parameter/Return值處理,以及可供函式內優化使用的暫存器數量都增加,善用這些額外暫存器可減少對外部記憶體存取的頻率,並讓編譯器優化時,更有空間去改善執行效能.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 1030px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>AArch64 Register</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"><strong>Special</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782"><strong>Role in the procedure call standard</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x0</strong><strong>…x7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">Parameter/result registers</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x8</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">Indirect result location register</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x9</strong><strong>…x15</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">Temporary registers</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x16</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">IP0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The first intra-procedure-call scratch register (can be used by call veneers and PLT code); at other times may be used as a temporary register.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x17</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">IP1</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The second intra-procedure-call temporary register (can be used by call veneers and PLT code); at other times may be used as a temporary register.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x18</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The Platform Register, if needed; otherwise a temporary register.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x19</strong><strong>…x28</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">Callee-saved registers</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x29</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">FP</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The Frame Pointer</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>x30</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">LR</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The Link Register</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>SP</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The Stack Pointer.</td></tr>
</tbody></table>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 1145px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="283"><strong>AArch32 Register</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"><strong>Special</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782"><strong>Role in the procedure call standard</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="283"><strong>r0</strong><strong>…r3</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">Parameter/result registers</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="283"><strong>r4</strong><strong>…r8<br />r9 (also as platform register)<br />r10,r11</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">Temporary registers</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="283"><strong>r12</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">IP</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The Intra-Procedure-call scratch register.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="283"><strong>r13</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">SP</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The second intra-procedure-call temporary register (can be used by call veneers and PLT code); at other times may be used as a temporary register.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="283"><strong>r14</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">LR</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">The Platform Register, if needed; otherwise a temporary register.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="283"><strong>r15</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">PC</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="782">Callee-saved registers</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下表,筆者嘗試從支援的暫存器/指令來分類AArch32 與 AArch64,以供簡要參考.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 820px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="143"><strong>Execution State</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="677"><strong>Note</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="143"><strong>AArch64</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="677">1,提供<strong>31</strong><strong>個64bits</strong>寬的General-Purpose Registers (from x0~x30,其中 x30亦可作為Procedure Link Registers)<br />2,提供64bits Program Counter(PC), Stack-Poiner(SP)與Exception-Link-Register (ELR)<br />3,提供<strong>32</strong><strong>個128bits</strong>寬的SIMD Vector 與 Scalar Floating-Point暫存器<br />4,定義ARMv8 EL0~EL3共4個Execution Privilege<br /><strong>5, </strong><strong>支援64bits Virtual-Addressing</strong><br />6, 定義一組PSTATE用以保存PE(Processing Element)狀態.</td></tr>
<tr class="over"><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="143"><strong>AArch32</strong></td><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="677">1,提供<strong>16</strong><strong>個32bits</strong>寬的General-Purpose Registers (from r0~r12, 其中r13=SP, r14=LR and r15=PC, 並且r14需同時供ELR與Procedure Link Registers之用)<br />2, 提供一個ELR,用以作為從Hyp-Mode的Exception返回之用.<br />3, 提供<strong>32</strong><strong>個64bits</strong>寬的Advanced SIMD Vector 與 Scalar Floating-Point暫存器<br />4, 提供A32與T32兩種指令集的組態<br /><strong>5, </strong><strong>使用32bits Virtual-Addressing</strong><br />6, 只使用CPSR (Current Program State Register)保存PE(Processing Element)狀態.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ARMv8共支援以下幾種Data types,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 248px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168"><strong>Data Type</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80"><strong>Length</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168">Byte <strong>(B)</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">8 bits.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168">Halfword<strong> (H)</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">16 bits.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168">Word<strong> (S)</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">32 bits.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168">Doubleword<strong> (D)</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">64 bits.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="168">Quadword<strong> (V)</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="bottom" width="80">128 bits.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而ARMv8通用暫存器.可區分32bits (Wn)與 64bits (Xn)兩類,可供程式執行依需求使用.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihsylFzELPCqS6FIgeEDrmMiUSbiNox1Xhty21qUoJlZ9WNgDXOW5z-ad4tHIAoPjzhZGiXZUd5hznmO5iOC8LJcs-imx_WHkFpFZCQ1LB68Kox98-2JRijmWoqdY8AfVIU34_Iang4PU/s1600/image003%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="189" data-original-width="863" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihsylFzELPCqS6FIgeEDrmMiUSbiNox1Xhty21qUoJlZ9WNgDXOW5z-ad4tHIAoPjzhZGiXZUd5hznmO5iOC8LJcs-imx_WHkFpFZCQ1LB68Kox98-2JRijmWoqdY8AfVIU34_Iang4PU/s1600/image003%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">至於SIMD/浮點數的部分,參考下圖可區分為8bits~128bits(16bits Half-Precision, 32bits Single-Precision and 64bits Double-Precision)不同的Size,並相容於IEEE 754.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBIWiOAmwQyPi8xfHk1hXy0kb8ckez6wsZO5PGmn8C2lzy-KMguT8KQuADe4JJiwQTU23ca6YKme82tb9K5oDN2JWzYhwbX27y9Fab96m6WDu2zeqskm4LnVDKOIkIbhT8Q2E7pweV3L8/s1600/image004%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="286" data-original-width="864" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBIWiOAmwQyPi8xfHk1hXy0kb8ckez6wsZO5PGmn8C2lzy-KMguT8KQuADe4JJiwQTU23ca6YKme82tb9K5oDN2JWzYhwbX27y9Fab96m6WDu2zeqskm4LnVDKOIkIbhT8Q2E7pweV3L8/s1600/image004%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ARMv8跟之前ARM處理器相比,最大的亮點之一就是Crypto加密指令集的支援,目前這部份的支援主要包括基於SIMD指令的 AES,SHA1與SHA2-256硬體加速指令,可參考如下簡表.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 853px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280"><strong>Crypto<br />New ARMv32 Instruction</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573"><strong>Explain</strong></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">AESD.8</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">AES single round decryption.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">AESE.8</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">AES single round encryption.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">AESIMC.8</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">AES inverse mix columns.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">AESMC.8</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">AES mix columns.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA1C.32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA1 hash update accelerator (choose).</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA1M.32</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA1 hash update accelerator (majority).</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA1P.32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA1 hash update accelerator (parity).</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA1H.32</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA1 hash update accelerator (rotate left by 30).</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA1SU0.32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA1 schedule update accelerator, first part</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA1SU1.32</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA1 schedule update accelerator, second part</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA256H.32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA256 hash update accelerator.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA256H2.32</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA256 hash update accelerator upper part.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA256SU0.32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA256 schedule update accelerator, first part</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">SHA256SU1.32</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">SHA256 schedule update accelerator, second part</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280">VMULL.P64</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="573">Polynomial multiply long, AES-GCM acceleration 64×64 to 128-bit.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
綜觀上述的介紹後,筆者嘗試把AArch32與AArch64兩個執行環境用如下圖加以說明,希望會比較好理解兩者的差異. 紅色部分為這次ARMv8新增的模塊,而黃色部分則為ARMv7既有支援的指令集範圍,可以看到在AArch32的架構下,A32與T32指令集間可以透過BX搭配Address bit 0 為1的方式由ARM Mode切換到Thumb Mode,並可透過BX指令從Thumb Mode切換回ARM Mode,兩者轉換的成本很低. 且ARMv8所支援的Crypto指令也同時在AArch32與AArch64模式下都有支援,可用於加速這兩類指令集模式下加解密指令效率.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而跟過去習知ARM Mode與Thumb Mode指令集切換最大的差異在於,在AArch32與AArch64兩者32bits/64bits執行模式切換時,目前ARMv8架構下只能透過觸發Exception的方式進行切換.也因此這表示一個應用程式撰寫時就必須決定自己是要處於32bits 或64bits的場景.如果希望可以享受到兩個模式下的好處,就必須要同時具備32bits Process與64bits Process,兩者之間再透過IPC(Inter-Process Communication)進行溝通.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh30j43jyFsLJ1RY6xLAu4aeOsAoN3Vba1Bhd3Lsyb3JyrEvP_SpT104C579gDIPjsYYCW-RFmP8X_sWgLSDnujY4E2O8CfTzO8pfJQEeeCD8JpUIdqGAah0AF97dumMd8Wiit44gotFBo/s1600/image005%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="397" data-original-width="572" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh30j43jyFsLJ1RY6xLAu4aeOsAoN3Vba1Bhd3Lsyb3JyrEvP_SpT104C579gDIPjsYYCW-RFmP8X_sWgLSDnujY4E2O8CfTzO8pfJQEeeCD8JpUIdqGAah0AF97dumMd8Wiit44gotFBo/s1600/image005%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">ARMv8把Execution Privilege區分為EL0到EL3共4個Level,根據目前的架構,會由下層系統的Execution State決定上層系統所在的模式.若下層系統為32bits, 則上層就只能為32bits</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSKUYC0D1dcuWopZjofJ1ZSH4IQkVMS5Ihitd3HFoQhYeoMMOorDt5JubClj6mpBG4XLjenl0T0_vboLUIkIq3CjwxNerAPcabhBOthizxCV6_NLdIgrBLwS5aCRNr-PqRnhN0FkwaY_0/s1600/image006%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="128" data-original-width="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSKUYC0D1dcuWopZjofJ1ZSH4IQkVMS5Ihitd3HFoQhYeoMMOorDt5JubClj6mpBG4XLjenl0T0_vboLUIkIq3CjwxNerAPcabhBOthizxCV6_NLdIgrBLwS5aCRNr-PqRnhN0FkwaY_0/s1600/image006%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">反之,若下層系統為64bits,上層就可選擇為32bits或64bits兩者之一,也因此若想要同時讓你的處理器軟體執行環境支援32bits Process與64bits Process,就必須要使用 64bits的Kernel執行環境.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpnvLkCtfL_kT5nHLpOZjO0XzYY8nV7owdXii6jrXoNXndjKP2z8BPFepeE3UaCOPmdIIz8pJv7K62YxPgHwYseS92v2528DHinETucBt4B_dzhWSIMSaQhGU6ev8HTMQi5uXzpLB8mZg/s1600/image007%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="128" data-original-width="488" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpnvLkCtfL_kT5nHLpOZjO0XzYY8nV7owdXii6jrXoNXndjKP2z8BPFepeE3UaCOPmdIIz8pJv7K62YxPgHwYseS92v2528DHinETucBt4B_dzhWSIMSaQhGU6ev8HTMQi5uXzpLB8mZg/s1600/image007%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
把ARMv8處理器的基礎差異說明後,接下來讓我們進一步嘗試說明ARMv8 AArch32與AArch64在執行時期的Memory體系為何,藉此可對應用程式運作有更進一步的了解.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>ARMv8 Memory Model</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Linux Kernel 3.16.3(in /arch/arm/mm/proc-v7-2level.S, <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/19381.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/19381.html</a>), ARM 32bits下會用TTBR0儲存當下User-Space行程所在的Page Table (也就是0xC0000000以下的記憶體空間),並用TTBR1儲存Kernel Space所在的Page Table (也就是0xC0000000以上的記憶體空間).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在ARMv8 64bits架構下,會透過EL1的TTBR0 (ttbr0_el1, in /arch/arm64/mm/proc.S, <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/22828.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/22828.html</a> )儲存當下User-Space行程所在的Page Table,與EL1的TTBR1儲存Kernel Space所在的Page Table,並會依據Page Size與32/64bits行程而有不同的記憶體空間配置. 參考如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJSiJv4SmiSgL45fW_LEop_f9MpyFUyJbACPReZXLIUoW_eVsAVy8hZUUwxxjEx1pOy4qVWWvWHEmKo4FDg258ZobeK_aY4oV-mzXLpW3plxCFesYkPOVjTAiAMg8AqN5pvSSMlZV_4AY/s1600/image008%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="554" data-original-width="592" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJSiJv4SmiSgL45fW_LEop_f9MpyFUyJbACPReZXLIUoW_eVsAVy8hZUUwxxjEx1pOy4qVWWvWHEmKo4FDg258ZobeK_aY4oV-mzXLpW3plxCFesYkPOVjTAiAMg8AqN5pvSSMlZV_4AY/s1600/image008%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">如下為原本大家習知32bits Linux Kernel記憶體定址方式,依據需求開發者可以配置為 User與Kernel Space各2GB的Layout,或是修改為 User與Kernel Space分別為3GB與1GB的定址方式.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5sJ09rVWmd3N7MuV101IzxX2uOXk2mwFSguvJg_zh5ivNh4tnmVHoW06wEelikZpsnZ5wyWveqBLQ-iV5gn8ygkiq9E8lMyWGj-zTExtHFmZ8cXVq99UuztPqJ7Fi7ID3M0BOlAoEnjI/s1600/image009%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="335" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5sJ09rVWmd3N7MuV101IzxX2uOXk2mwFSguvJg_zh5ivNh4tnmVHoW06wEelikZpsnZ5wyWveqBLQ-iV5gn8ygkiq9E8lMyWGj-zTExtHFmZ8cXVq99UuztPqJ7Fi7ID3M0BOlAoEnjI/s1600/image009%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">但由於ARM 64bits Kernel的分頁(Page)有分4KB 與 64KB兩種大小,參考 TASK_SIZE_64 (/arch/arm64/include/asm/memory.h,http://hala01.com/src/linux/linux-3.16.3/HTML/S/22730.html#L62 )所指定的數值,其中當分頁大小為4KB時,決定TASK_SIZE_64大小的VA_BITS會等於 39,也就是2^39大小的Task空間(=512GB),若分頁大小為64KB時,則TASK_SIZE_64對應的VA_BITS會等於 42,也就是2^42大小的Task空間(=4TB).</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzibOTbHSmiM2EWVmxyb9HTZIujVHtFatdpoLyP7gEG1OT4kLxTqsAbcl2PDE2B0MgP0Szr1evmSHVMAEPB75uaYApch3KFtrQnvGLoNdc3enWukF1xuxqYxXnrF5oeOF4IL2FdjI_Akc/s1600/image010%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="433" data-original-width="894" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzibOTbHSmiM2EWVmxyb9HTZIujVHtFatdpoLyP7gEG1OT4kLxTqsAbcl2PDE2B0MgP0Szr1evmSHVMAEPB75uaYApch3KFtrQnvGLoNdc3enWukF1xuxqYxXnrF5oeOF4IL2FdjI_Akc/s1600/image010%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
同時, Kernel Space的範圍會透過 PAGE_OFFSET=(UL(0xffffffffffffffff) << (VA_BITS – 1))取得(in /arch/arm64/include/asm/memory.h , http://hala01.com/src/linux/linux-3.16.3/HTML/S/22730.html#L49), 且ARM64 Linux Kernel下的high_memory會等於裝置所配置的實體記憶體大小加上PAGE_OFFSET,這塊記憶體可用於線性Memory Mapping實體記憶體與核心虛擬記憶體空間. 若有配置Sparse Memory Virtual memmap用以優化 pfn_to_page/page_to_pfn 流程,則vmemmap 起點為Linear Mapping記憶體的起點virt_to_page(PAGE_OFFSET)終點會等於virt_to_page(high_memory).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當分頁大小為4KB時,決定PAGE_OFFSET大小的VA_BITS會等於 39,因此 PAGE_OFFSET=(UL(0xffffffffffffffff) << (39 – 1))= 0xFFFFFFC000000000,而Kernel Driver所在的區間MODULES_END =PAGE_OFFSET=0xFFFFFFC000000000 與 MODULES_VADDR=MODULES_END – SZ_64M=0xFFFFFFBFFC000000, 並且VMALLOC_START= (UL(0xffffffffffffffff) << VA_BITS)= (UL(0xffffffffffffffff) << 39)= 0xFFFFFF8000000000,與VMALLOC_END=(PAGE_OFFSET – UL(0x400000000) – SZ_64K)= 0xFFFFFFBBFFFF0000.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若分頁大小為64KB時,則PAGE_OFFSET對應的VA_BITS會等於 42,也就是PAGE_OFFSET=(UL(0xffffffffffffffff) << (42 – 1))= 0xFFFFFE0000000000, 而Kernel Driver所在的區間MODULES_END =PAGE_OFFSET=0xFFFFFE0000000000與 MODULES_VADDR=MODULES_END – SZ_64M=0xFFFFFDFFFC000000. 並且VMALLOC_START= (UL(0xffffffffffffffff) << VA_BITS)= (UL(0xffffffffffffffff) << 42)= 0xFFFFFC0000000000,與VMALLOC_END=(PAGE_OFFSET – UL(0x400000000) – SZ_64K)= 0xFFFFFDFBFFFF0000.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Kernel Memory Mapping的概念,可參考如下示意圖</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYJiLGXNuS39rITnRZkcyNspX7UqsIAc14tED8jqafUDyu6r7D4jY5UXu-qDHaunp5-WipZOT5P3gC6sJH3OMa7U_3HqNI8qWmpcFEQGtkvOHQpQ5pW3qmFHarVYoxHrxWvdG-wI7-u1I/s1600/image0114%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="722" data-original-width="952" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYJiLGXNuS39rITnRZkcyNspX7UqsIAc14tED8jqafUDyu6r7D4jY5UXu-qDHaunp5-WipZOT5P3gC6sJH3OMa7U_3HqNI8qWmpcFEQGtkvOHQpQ5pW3qmFHarVYoxHrxWvdG-wI7-u1I/s1600/image0114%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
秉持一貫有Source Code有真相的原則,讓我們從Linux Kernel Source Code的角度來進一步的說明原委,首先從ARM64架構下一個應用程式從執行檔開始貼到記憶體布局的流程來加以說明,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, 當使用者或應用載入一個新的程式時(例如呼叫load_elf_binary),就會透過函式setup_new_exec(in /fs/exec.c, <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/8148.html#L1101" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/8148.html#L1101</a> )來為新的Process的記憶體布局進行配置.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 在函式setup_new_exec中,則會呼叫arch_pick_mmap_layout(current->mm);進入函式arch_pick_mmap_layout(in /arch/arm64/mm/mmap.c, <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L84" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L84</a> ),依據不同的處理器差異<strong>(ARM 32bits/64bits,MIPS,Parisc,PowerPC,S390,Sparc,Tile,x86,..etc)</strong>,為目前的Process 記憶體布局進行配置</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, 由於本文著重於ARM 64bits,因此會以ARM64中的函式 arch_pick_mmap_layout(in /arch/arm64/mm/mmap.c, <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L84" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L84</a> )為主加以說明,首先這函式可以分為兩個部分</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
void arch_pick_mmap_layout(struct mm_struct *mm)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>if (mmap_is_legacy())</strong> {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mm->mmap_base = TASK_UNMAPPED_BASE;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mm->get_unmapped_area = arch_get_unmapped_area;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} <strong>else</strong> {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mm->mmap_base = mmap_base();</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mm->get_unmapped_area = arch_get_unmapped_area_topdown;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3.1, <strong>若if (mmap_is_legacy())</strong><strong>成立</strong>è</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此時Task的mm->get_unmapped_area為arch_get_unmapped_area(in /mm/mmap.c, <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/9939.html#L1873" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/9939.html#L1873</a> ),表示該Task Process每一個新的Memory Mapping (包括應用程式本身,動態函式庫,MMAP配置…等),都會由低位址往高位址依序配置而上,這比較像是最早對於原本對於MMAP的概念,也就是Legacy的作法.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對應到 32bits Kernel, Task 的mm->mmap_base會等於TASK_UNMAPPED_BASE,若此時Kernel Space起點為0xC0000000,則會從0x40000000為起點.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若是 64bits Kernel, 則 32bits Task的TASK_UNMAPPED_BASE 會等於(PAGE_ALIGN(TASK_SIZE / 4))(in /arch/arm64/include/asm/memory.h, <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/22730.html#L65" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/22730.html#L65</a> ),其中因為TASK_SIZE_32為0x100000000,因此會跟32bits Kernel下的32bits Task一樣都以0x40000000為起點.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若為64bits Kernel下的64bits Task, 由於 TASK_SIZE_64 等於 (UL(1) << VA_BITS),若該64bits Kernel使用4KB Page為單位,則VA_BITS 等於39 (若使用64KB Page為單位,則VA_BITS 等於42),對應到TASK_SIZE_64 等於(UL(1) << VA_BITS),因此在4KB Page設定下, TASK_UNMAPPED_BASE 透過(PAGE_ALIGN(TASK_SIZE / 4))會等於0x2000000000 (若使用64KB Page,則為0x10000000000), 由於這些組合比較多,筆者把上述的組合繪製如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8swo-z5K6YO9-ej4fs9Cul73nsM25DFkAT9LecnlGDRJv0c8DjbSXmLlDVQkYhr1dZ6S3ZLjuOh5qsICK48xCtpBYcYq2vEPhT7KeEckfVAEPa0omtXTkFLYbY5TtGi5MfNAnaIqiCNI/s1600/image0122%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="667" data-original-width="977" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8swo-z5K6YO9-ej4fs9Cul73nsM25DFkAT9LecnlGDRJv0c8DjbSXmLlDVQkYhr1dZ6S3ZLjuOh5qsICK48xCtpBYcYq2vEPhT7KeEckfVAEPa0omtXTkFLYbY5TtGi5MfNAnaIqiCNI/s1600/image0122%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3.2,<strong>若if (mmap_is_legacy()) </strong><strong>不成立</strong>è</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此時Task的mm->get_unmapped_area為arch_get_unmapped_area_topdown(in /mm/mmap.c, <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/9939.html#L1909" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/9939.html#L1909</a> ),表示該Task Process每一個新的Memory Mapping (包括應用程式本身,動態函式庫,MMAP配置…等),都會反過來,由高位址往低位址依序配置而下,這是屬於目前比較新的Android手機環境所要求的作法. 在這架構上, Task 的mm->mmap_base會透過呼叫函式 <strong>“unsigned long mmap_base(void)”</strong> (in /arch/arm64/mm/mmap.c , <a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L68" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L68</a>) 決定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為函式mmap_base的實作</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>static unsigned long mmap_base(void)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>{</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>unsigned long gap = rlimit(RLIMIT_STACK);</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>if (gap < MIN_GAP)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>gap = MIN_GAP;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>else if (gap > MAX_GAP)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>gap = MAX_GAP;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>return PAGE_ALIGN(STACK_TOP – gap – mmap_rnd());</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中, gap = rlimit(RLIMIT_STACK) = rlimit(3)會透過ACCESS_ONCE(tsk->signal->rlim[limit].rlim_cur) 取得目前系統的配置數值.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考如下代碼, 其中, MAX_GAP會等於 (STACK_TOP/6*5),以 ARM 64bits下的4KB Page來說這個值為(TASK_SIZE_64/6*5) = ((UL(1) << VA_BITS)/6*5)=0x6AAAAAAAA9 (in arch/arm64/mm/mmap.c,http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L37),而 MIN_GAP會等於 (SZ_128M + ((STACK_RND_MASK << PAGE_SHIFT) + 1)) 以 ARM 64bits下的4KB Page來說這個值為(0x08000000 + (((0x3ffff >> (12 – 12)) << 12) + 1))=0x47FFF001 (in arch/arm64/mm/mmap.c,http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L36)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/*</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* Leave enough space between the mmap area and the stack to honour ulimit in</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* the face of randomisation.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>*/</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#define MIN_GAP (SZ_128M + ((STACK_RND_MASK << PAGE_SHIFT) + 1))</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#define MAX_GAP (STACK_TOP/6*5)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在ARM 64bits搭配4KB Page配置下, 函式mmap_rnd 實作(in arch/arm64/mm/mmap.c ,http://hala01.com/src/linux/linux-3.16.3/HTML/S/22812.html#L58 ),其中 rnd = (long)get_random_int() & (STACK_RND_MASK >> 1) , 而get_random_int函式會透過MD5 Hash機制回傳一個整數任意值, STACK_RND_MASK會等於 (0x3ffff >> (PAGE_SHIFT – 12)) =0x3ffff (in /arch/arm64/include/asm/elf.h ,http://hala01.com/src/linux/linux-3.16.3/HTML/S/22803.html#L157).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因此, rnd 會等於整數隨機任意值 & 0x3ffff,之後再進行rnd << (PAGE_SHIFT + 1)等於 rnd << (12 + 1)= 0x3ffff <<13 =0x7fffe000.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/*</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* Since get_random_int() returns the same value within a 1 jiffy window, we</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* will almost always get the same randomisation for the stack and mmap</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* region. This will mean the relative distance between stack and mmap will be</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* the same.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* To avoid this we can shift the randomness by 1 bit.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>*/</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>static unsigned long mmap_rnd(void)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>{</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>unsigned long rnd = 0;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>if (current->flags & PF_RANDOMIZE)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>rnd = (long)get_random_int() & (STACK_RND_MASK >> 1);</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>return rnd << (PAGE_SHIFT + 1);</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式mmap_base 最後回傳的PAGE_ALIGN(STACK_TOP – gap – mmap_rnd()) = AGE_ALIGN(0x7ffffffffff – gap – 0x7fffe000),對應到實際的產品上,會是如下的Layout</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPbP9skFZhRgZnr1jHo132ZDCMlhD4x8ATkeudfs2lzVEVXPSzSpilIgXAkTXW931KU3KfuyClP8KS8CT5eZ83Vn7PMhKfVre-r2UtvropW4qdH8gY8u3eAu4-XQDBh19jGooU8ylzYHc/s1600/image0133%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="660" data-original-width="977" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPbP9skFZhRgZnr1jHo132ZDCMlhD4x8ATkeudfs2lzVEVXPSzSpilIgXAkTXW931KU3KfuyClP8KS8CT5eZ83Vn7PMhKfVre-r2UtvropW4qdH8gY8u3eAu4-XQDBh19jGooU8ylzYHc/s1600/image0133%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,讓我們從CPRS與Process State來進一步了解ARMv8的系統程式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>從</strong><strong> CPSR </strong><strong>看</strong><strong> PSTATE (Process state)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要了解ARMv7 與ARMv8 的System Model最好方式就是從 Current Program Status Register (CPSR) 來看兩者的差異,首先筆者參考 ARMv8 ARM文件(<a href="http://www.cs.utexas.edu/~peterson/arm/DDI0487A_a_armv8_arm_errata.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.cs.utexas.edu/~peterson/arm/DDI0487A_a_armv8_arm_errata.pdf</a>) 與ARMv7 Architecture Reference Manual的文件(<a href="http://liris.cnrs.fr/~mmrissa/lib/exe/fetch.php?media=armv7-a-r-manual.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://liris.cnrs.fr/~mmrissa/lib/exe/fetch.php?media=armv7-a-r-manual.pdf</a>), 並以此為基礎來加以說明.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據ARM的文件, ARMv7 , ARMv8 32bits 與 ARMv8 64bits的CPSR相比有如下的差異. 最基礎來看就是ARMv7與ARMv8 32bits的比較,會看到ARMv8 32bits多了Bit 20:IL新的PSR屬性. 而ARMv8 32bits與ARMv8 64bits相比則是少了IT與GE屬性,但卻多了D屬性(取代原本32bits下的E屬性).</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 1088px;"><tbody>
<tr class="alt"><td rowspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><strong>ARMv8</strong><strong><br />AArch64</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>31</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>30</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>29</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>28</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>27</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>26</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>25</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>24</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>23</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>22</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>21</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>20</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>19</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>18</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>17</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>16</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>15</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>14</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>13</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>12</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>11</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>10</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>9</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>8</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>6</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>5</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><strong>4</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>3</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>2</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>1</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>0</strong></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>N</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>Z</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>C</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>V</strong></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="180"><strong>RES0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>SS</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>IL</strong></td><td colspan="10" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="300"><strong>RES0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>D</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>A</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>I</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>F</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>RES0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><strong>0</strong></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120"><strong>M[3:0]</strong></td></tr>
<tr class="alt"><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="150"><strong>Condition Flag</strong></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="540"><strong></strong></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><strong>Mask bits</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong></strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><strong>M[4]</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong></strong></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><strong></strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td></tr>
<tr class="alt"><td rowspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><strong>ARMv8</strong><strong><br />AArch32</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>31</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>30</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>29</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>28</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>27</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>26</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>25</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>24</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>23</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>22</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>21</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>20</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>19</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>18</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>17</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>16</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>15</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>14</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>13</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>12</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>11</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>10</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>9</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>8</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>6</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>5</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><strong>4</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>3</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>2</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>1</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>0</strong></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>N</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>Z</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>C</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>V</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>Q</strong></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="60"><strong>IT[1:0]</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>J</strong></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><strong>RES0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>IL</strong></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120"><strong>GE[3:0]</strong></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="180"><strong>IT[7:2]</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>E</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>A</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>I</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>F</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>T</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><strong>1</strong></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120"><strong>M[3:0]</strong></td></tr>
<tr class="alt"><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="150"><strong>Condition Flag</strong></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="540"><strong></strong></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><strong>Mask bits</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong></strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><strong>M[4]</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong></strong></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><strong></strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"></td></tr>
<tr class="alt"><td rowspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><strong>ARMv7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>31</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>30</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>29</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>28</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>27</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>26</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>25</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>24</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>23</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>22</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>21</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>20</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>19</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>18</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>17</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>16</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>15</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>14</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>13</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>12</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>11</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>10</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>9</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>8</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>6</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>5</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><strong>4</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>3</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>2</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>1</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>0</strong></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>N</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>Z</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>C</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>V</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>Q</strong></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="60"><strong>IT[1:0]</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>J</strong></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120"><strong>Reserved<br />RAZ/SBZP</strong></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120"><strong>GE[3:0]</strong></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="180"><strong>IT[7:2]</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>E</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>A</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>I</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>F</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>T</strong></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><strong>M[4:0]</strong></td></tr>
<tr class="alt"><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="150"><strong>Condition Flag</strong></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="540"><strong></strong></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><strong>Mask bits</strong></td><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><strong></strong></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirwz2pv5F5hDc4Ky72NRIKIr8mBvlUkip8b05FGF2quMWXH_nnP4aYZhSVy5o-zmQc8giE_dtIbPQns2Sskfsn2x2j1ZcyYXJ4JTyaggpN1TL7V2Fk2VsYHGumbUFJqu8ACfTpo0j6iyg/s1600/table%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="316" data-original-width="1089" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirwz2pv5F5hDc4Ky72NRIKIr8mBvlUkip8b05FGF2quMWXH_nnP4aYZhSVy5o-zmQc8giE_dtIbPQns2Sskfsn2x2j1ZcyYXJ4JTyaggpN1TL7V2Fk2VsYHGumbUFJqu8ACfTpo0j6iyg/s1600/table%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先, 簡述PSR(Program Status Register) 程式狀態暫存器的意義,這個暫存器主要用來紀錄程序狀態之用,包括反映出目前所處的處理器模式,指令集狀態,以及反應出條件(Cond.)執行指令判斷執行的依據.舉個例子來說,在ARMv7 或ARMv8 32bits下, 當我們從CPSR的4-0bits取出值為b10111就可以知道目前所在的Exception Handler,是發生了Abort,之後再判斷SPSR的4-0bits,若為b10011(SVC Mode)或b10000(User Mode),就可以知道在觸發這個Abort前,處理器是在執行哪一個模式下的程式碼,如果擔心有因為Exception Handle設計不當導致的Abort重入問題,也可以透過CPSR/SPSR前後模式比對,知道是不是Abort重入,可以鎖定潛在的系統問題加以解決. 如下簡述每個欄位的意義</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 1417px;"><tbody>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="353"><strong>ARMv7</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong></strong></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="385"><strong>ARMv8 AArch32</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong></strong></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="528"><strong>ARMv8 AArch64</strong></td><td height="27" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97"><strong>功能</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257"><strong>說明</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>位元</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><strong>功能</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287"><strong>說明</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>位元</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><strong>功能</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433"><strong>說明</strong></td><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">Mode[3:0]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Mode Bits模式位元<br />b10000(0×0010) -User Mode<br />b10001(0×0011)- FIQ Mode<br />b10010(0×0012)-IRQ Mode<br />b10011(0×0013)-Supervisor Mode<br />b10111(0×0017)-Abort Mode<br />b11011(0x001b)-Undefined Mode<br />b11111(0x001F)-System Mode<br />b10110(0×0016)-Secure Monitor</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>3-0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">Mode[3:0]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287"><strong>the same as ARMv7</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>3:0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">Mode[3:0]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Mode Bits模式位元<br />0b0000 – EL0t<br />0b0100 – EL1t<br />0b0101 – EL1h<br />0b1000 – EL2t<br />0b1001 – EL2h<br />0b1100 – EL3t<br />0b1101 – EL3h<strong><br />M[3:2] holds the Exception Level.<br />M[1] is unused<br />M[0] is used to select the SP: 0 means the SP is always SP0 and 1 means the exception SP is determined by the EL.</strong></td><td height="289" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">Mode[4]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">1</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>4</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">Mode[4]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287"><strong>= 1 = Exception taken from AArch32</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>4</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">Mode[4]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433"><strong>= 0 = Exception taken from AArch64</strong></td><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">T</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Thumb state bit<br />0=ARM<br />1=Thumb</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>5</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">T</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287"><strong>the same as ARMv7</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>5</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">RES0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Reserved</td><td height="72" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">F</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">FIQ Disable<br />1=禁止<br />0=允許</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>6</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">F</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287"><strong>the same as ARMv7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>6</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">F</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">FIQ Disable<br />1=禁止<br />0=允許</td><td height="74" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">I</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">IRQ Disable<br />1=禁止<br />0=允許</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>7</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">I</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287"><strong>the same as ARMv7</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>7</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">I</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">IRQ Disable<br />1=禁止<br />0=允許</td><td height="74" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">A</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Asynchronous data abort mask bit.<br />1=禁止<br />0=允許</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>8</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">A</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287"><strong>the same as ARMv7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>8</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">A</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">SError (System Error) mask bit. The possible values of this bit are:<br />1=禁止<br />0=允許</td><td height="98" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">E</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Endianness execution state bit. Controls the load and store endianness for data accesses:<br />0=Little-endian operation<br />1=Big-endian operation.</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>9</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">E</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287"><strong>the same as ARMv7</strong><strong><br /></strong><strong>但由於</strong><strong>ARMv8</strong><strong>有</strong><strong>EL0~EL3,</strong><strong>這個</strong><strong>Bit</strong><strong>可以用來表示目前所在的</strong><strong>EL</strong><strong>是支援</strong><strong>Little or Big-endian</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>9</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">D</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Process state D mask. 主要包含有以下的組合<br />0 = 允許 Debug exceptions from Watchpoint, Breakpoint, and Software step debug events targeted at the current exception level .<br />1 = 禁止 Debug exceptions from Watchpoint, Breakpoint, and Software step debug events targeted at the current exception level.<br />(若除錯Target EL沒有大於目前所在的Current EL,就不會Set這個Bit,所以當這D bit為0,就表示Current EL可以除錯當下的Target EL.)</td><td height="173" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">IT[7:2]</td><td rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">If-Then execution state bits for the Thumb IT (If-Then) instruction.</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>10</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">c</td><td rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">IT state bits</td><td rowspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>19:10</strong></td><td rowspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">RES0</td><td rowspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Reserved</td><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>11</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">b</td><td height="27" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>12</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">a</td><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>15-13</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">IT_cond</td><td height="27" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">GR[3:0]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Greater than or Equal flags</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>19-16</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">GR[3:0]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Greater than or Equal flags</td><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">RAZ/SBZP</td><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Reserved</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>20</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">IL</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Illegal Execution State bit. Shows the value of PSTATE.IL immediately before the exception was taken.</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>20</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">IL</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Illegal Execution State bit. Shows the value of PSTATE.IL immediately before the exception was<br />taken.</td><td height="72" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>23:21</strong></td><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">RES0</td><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Reserved</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>21</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">SS</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Software step. Indicates whether software step was enabled when an exception was taken.</td><td height="48" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr><td rowspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>27:22</strong></td><td rowspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">RES0</td><td rowspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Reserved</td><td height="30" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">J</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Jazelle State Bit</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>24</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">J</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Jazelle State Bit</td><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">IT[1:0]</td><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">If-Then execution state bits for the Thumb IT (If-Then) instruction.</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>25</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">e</td><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">IT state bits</td><td height="27" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>26</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">d</td><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">Q</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Cumulative saturation bit.</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>27</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">Q</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Sticky Overflow</td><td height="27" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">V</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Overflow condition flag.</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>28</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">V</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Overflow</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>28</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">V</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Set to the value of the V condition flag on taking an exception to EL1, and copied to the V condition<br />flag on executing an exception return operation in EL1.</td><td height="72" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">C</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Carry condition flag</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>29</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">C</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Carry/Borrow/Extend</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>29</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">C</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Set to the value of the C condition flag on taking an exception to EL1, and copied to the C condition<br />flag on executing an exception return operation in EL1.</td><td height="72" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">Z</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Zero condition flag</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>30</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">Z</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Zero</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>30</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">Z</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Set to the value of the Z condition flag on taking an exception to EL1, and copied to the Z condition<br />flag on executing an exception return operation in EL1.</td><td height="72" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="97">N</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257">Negative condition flag</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><strong>31</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98">N</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="287">Negative/Less than</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><strong>31</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95">N</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">Set to the value of the N condition flag on taking an exception to EL1, and copied to the N condition<br />flag on executing an exception return operation in EL1.</td><td height="72" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="0"></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibiKdNIMz2GoNDP9OuKCWxH3hVGF51E2rygn6gZ1DFgYJJxoHK1tIMZOtfACeKfuRXSD8JYRgYle1ktPNkgL0_iVX15XpTJFdGFxgmQ837JEcpCdQLwlDvEJyLCvwrocRNCgUS0HX4k-w/s1600/table2%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1439" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibiKdNIMz2GoNDP9OuKCWxH3hVGF51E2rygn6gZ1DFgYJJxoHK1tIMZOtfACeKfuRXSD8JYRgYle1ktPNkgL0_iVX15XpTJFdGFxgmQ837JEcpCdQLwlDvEJyLCvwrocRNCgUS0HX4k-w/s1600/table2%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若M[4]為1,則表示是在ARMv7原本的32bits Mode與ARMv8 AArch32下,我們可以直接透過M[4:0]判定目前是在哪個CPU State(User, SVC, Data Abort, Undef….etc)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但若M[4]為0則表示當下是在ARMv8 AArch64下,會變成改用M[3:0]中的M[3:2]可用以表示當下所在的Exception Level.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而M[0]若為0表示預設使用SP_EL0作為Stack Pointer,若1則預設使用每個Exception Level對應的SP_ELx作為Stack Pointer. 當所在的Exception Level為EL0,則此時SP(Stack Pointer)就會預設定義為SP_EL0,通常每個Exception Level都有其所對應的SP暫存器,例如SP_ELx暫存器就可用於儲存每個不同Exception Level所對定的專屬 SP 置存器,例如 EL1使用 SP_EL1, EL2使用SP_EL2而EL3使用SP_EL3. 在軟體執行的過程中,可以透過 “MSR SPSel, #Imm1”指令選擇要使用每個Exception Level對應的SP_ELx暫存器還是統一只使用SP_EL0暫存器作為當下的Stack Pointer.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
針對Debug的需求,AArch64下可以透過 Syndrome Register在切換不同CPU Exception Level時,判定當下系統觸發Exception Level轉換的原因,同樣的,要有Code才有真相,因此讓我們參考 arch/arm64/kernel/entry.S (<a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/22867.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/22867.html</a> ),可知在Linux Kernel EL1 Entry的實作,會透過讀取ESR_EL1當做Exception Mode的判定,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
el1_sync:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel_entry 1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mrs x1, esr_el1 // read the syndrome register</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lsr x24, x1, #ESR_EL1_EC_SHIFT // exception class</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp x24, #ESR_EL1_EC_DABT_EL1 // data abort in EL1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b.eq el1_da</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp x24, #ESR_EL1_EC_SYS64 // configurable trap</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b.eq el1_undef</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp x24, #ESR_EL1_EC_SP_ALIGN // stack alignment exception</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b.eq el1_sp_pc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp x24, #ESR_EL1_EC_PC_ALIGN // pc alignment exception</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b.eq el1_sp_pc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp x24, #ESR_EL1_EC_UNKNOWN // unknown exception in EL1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b.eq el1_undef</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp x24, #ESR_EL1_EC_BREAKPT_EL1 // debug exception in EL1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b.ge el1_dbg</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b el1_inv</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示為ARMv8 64bits下, ESR (Exception Syndrome Register)的格式內容,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 1122px;"><tbody>
<tr class="alt"><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="162"><strong>Format of the ESR_ELx registers</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>31</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>30</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>29</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>28</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>27</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>26</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>25</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>24</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>23</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>22</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>21</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>20</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>19</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>18</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>17</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>16</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>15</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>14</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>13</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>12</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>11</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>10</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>9</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>8</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>6</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>5</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>4</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>3</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>2</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>1</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>0</strong></td></tr>
<tr class=""><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="180"><strong>EC</strong><strong>(Exception Class)</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="30"><strong>IL</strong></td><td colspan="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="750"><strong>ISS</strong><strong> (Instruction Specific Syndrome)</strong></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGP9Lz223s_v9e2kc5BWppbPxtlq16XB7DDvTSPKkHyt2d7c6t4cdpvAbziIuBsLM8enLYmczN-4yac-6ByDMqfPARlJtSTQXB8kXGtWv7IAGK104UmN5oolLh0fyLPHfd5ICOEcoVxfQ/s1600/table3%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="56" data-original-width="1122" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGP9Lz223s_v9e2kc5BWppbPxtlq16XB7DDvTSPKkHyt2d7c6t4cdpvAbziIuBsLM8enLYmczN-4yac-6ByDMqfPARlJtSTQXB8kXGtWv7IAGK104UmN5oolLh0fyLPHfd5ICOEcoVxfQ/s1600/table3%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者依據ARM文件簡述內容意義如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
EC[31:26]: 表示Exception Class, 用以表示觸發這次Exception的原因 (例如從EL0->EL1,…etc)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
IL[25]: 表示Instruction Length, 0表示 16bits Trapped-Instruction, 1表示32bits Trapped-Instruction.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
è以Software Breakpoint Instruction而言, 0表示16bits T32(Thumb) BKPT指令觸發,1表示32bits A32(ARM) BKPT或A64 BRK指令觸發.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ISS [24:0]: 用以作為Instruction Specific Syndrome 欄位,可在AArch32或AArch64不同模式下,有不同欄位的顯示意義.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ESR_ELx是一個AArch64下CPU Mode基礎狀態判定的基礎,依據Exception Level的改動, AArch64有支援ESR_EL1, ESR_EL2, and ESR_EL3用以提供給 EL0->EL1, EL1->EL2與EL2->EL3模式轉換過程的CPU State判斷. 但簡單來說,最直覺的使用就是參與EC與IL欄位,依據目前3.16版本的Linux Kernel Source Code的arch/arm64/include/asm/esr.h (<a href="http://hala01.com/src/linux/linux-3.16.3/HTML/S/22702.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.16.3/HTML/S/22702.html</a> )來說,會根據EC定義如下的處理器模式組態作為EL0<->EL1的判斷之用.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPB884UDH4IXD8fuaDE7MaMpzBKK2vMOGmfofJhvBAvGXs5_61o-YyyA4Y9Cz8NFRpQI7jliQjyN42L6n-YhgKDlvGKSE5K5uy6Y8FmE6WtHij-OJmvFlYz_I1Nhyphenhyphenk7JFAuXwVMsE5JlY/s1600/image013%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="945" data-original-width="621" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPB884UDH4IXD8fuaDE7MaMpzBKK2vMOGmfofJhvBAvGXs5_61o-YyyA4Y9Cz8NFRpQI7jliQjyN42L6n-YhgKDlvGKSE5K5uy6Y8FmE6WtHij-OJmvFlYz_I1Nhyphenhyphenk7JFAuXwVMsE5JlY/s1600/image013%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以Linux Kernel 的EL1 mode handlers來說共支援以下的Exception Class</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 1470px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="542"><strong>Exception Class in Linux Kernel EL1</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="928"><strong>Notes</strong></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="542"><strong>ESR_EL1_EC_UNKNOWN </strong>(0x00)<strong><br />(unknown exception in EL1)</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="928">Unknown reason (用以包括其它尚未被Exception Class包括到的Exception類型)<br />例如像是<br />1, 錯誤的指令集編碼 (像是 Undefined Instruction..etc),不管是在Debug or Non-Debug State.<br />2, Attempted execution of:<br />— An HVC instruction when disabled by HCR_EL2.HCD or SCR_EL3.HCE.<br />— An SMC instruction when disabled by SCR_EL3.SMD.<br />— An HLT instruction when disabled by EDSCR.HDE<br />3, Attempted execution of an MSR or MRS to SP_EL0 when the value of SPSel.SP is 0.<br />4, …(還有許多類型 就不一一敘述.)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="542"><strong>ESR_EL1_EC_SYS64 </strong>(0x18)<strong><br />(configurable trap)</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="928">MSR, MRS, or System instruction execution, that is not reported using EC 0x00, 0x01, or 0x07<br />Exception from MSR, MRS, or System instruction execution in AArch64 state</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="542"><strong>ESR_EL1_EC_PC_ALIGN </strong>(0x22)<strong><br />(pc alignment exception)</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="928">Misaligned PC exception</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="542"><strong>ESR_EL1_EC_DABT_EL1 (</strong>0x25)<strong><br />(data abort in EL1)</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="928">Data Abort taken without a change in Exception level</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="542"><strong>ESR_EL1_EC_SP_ALIGN </strong>(0x26)<strong><br />(stack alignment exception)</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="928">Stack Pointer Alignment exception</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="542"><strong>ESR_EL1_EC_BREAKPT_EL1</strong>(0x31)<strong><br />(debug exception in EL1)</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="928">Breakpoint exception taken without a change in Exception level</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqqbfyiNQS-D68uG1bS8ThfS8VWobI2MDQ0xgXYT7eeOEIuZvK9vFIC212RMGnSeg0CRDuLPNMPVKu26JPiM5_ND9UZd0HSuAhepi4Gad32N7AgsrSnlUjaAa3VV2FC51VfhC03kQURTI/s1600/table4%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="544" data-original-width="1471" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqqbfyiNQS-D68uG1bS8ThfS8VWobI2MDQ0xgXYT7eeOEIuZvK9vFIC212RMGnSeg0CRDuLPNMPVKu26JPiM5_ND9UZd0HSuAhepi4Gad32N7AgsrSnlUjaAa3VV2FC51VfhC03kQURTI/s1600/table4%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在簡述ARM Process State之後,讓我們進一步說明ARMv8 Security Model.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>ARMv8 Security Model</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
針對Security的需求, ARMv8的系統軟體設計可以提供如下Secure-Mode與Non-Secure Mode的組態,如前面所提到的,若底層EL(Exception Level)為32bits,則上層EL的軟體就只能是32bits.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4n4nMs8RUiojWN95H3hObwfwirj21rp53H6IqLJwQAidwdUz8v5rgz-_lQIMHkgDdpEPZ4SC10dxUByiy_VCLzFk8gvWds-D3BCIyqPg5zN1kLrEJA9aDzbw0On51B68Y9J3Tkubb_Cw/s1600/image014%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="629" data-original-width="927" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4n4nMs8RUiojWN95H3hObwfwirj21rp53H6IqLJwQAidwdUz8v5rgz-_lQIMHkgDdpEPZ4SC10dxUByiy_VCLzFk8gvWds-D3BCIyqPg5zN1kLrEJA9aDzbw0On51B68Y9J3Tkubb_Cw/s1600/image014%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">若底層的EL為64bits,則上層EL就可以依據需求選擇為 32bits或是64bits 的軟體模塊.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguu9nQSBs6Eoyo-9eId6xRpF3IttJvo5y0RwXYebgT_iUZizltZ719i9TxCEHXL0DZSqbn6Tg8STvzJAI0stDzSxavbhKpR84IJrgDghFjUhac9ueTvF9C_68ZdrNvR43TmhP8l-Stbl8/s1600/image015%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="629" data-original-width="927" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguu9nQSBs6Eoyo-9eId6xRpF3IttJvo5y0RwXYebgT_iUZizltZ719i9TxCEHXL0DZSqbn6Tg8STvzJAI0stDzSxavbhKpR84IJrgDghFjUhac9ueTvF9C_68ZdrNvR43TmhP8l-Stbl8/s1600/image015%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在不久的未來,即將有許多配備ARMv8的Android/Linux裝置被普及到市面上,除了更好的執行效率外,64bits更大的記憶體定址能力,也讓原本32bits High/Low-Zone體系被改變,開發者也省去一些力氣在記憶體Zone區的優化上,但對使用者來說,隨著更多搭配64bits優化方案的日趨成熟,像是編譯器, ART執行環境或第三方應用軟體的優化,相信所帶來的使用者體驗也會更佳.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後,本文謹涉及基礎的ARMv8與部分軟體概念,對有志於進一步探究ARMv8的初學者希望能有所助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com4tag:blogger.com,1999:blog-1668810802505961314.post-44484510015289191222017-06-04T10:14:00.004-07:002017-06-04T10:14:46.740-07:00Android 4.3安全機制探討.<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android 4.3安全機制探討.</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android 4.3</strong><strong>安全機制探討</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<a href="mailto:hlchou@gmail.com" style="color: #666666; font-weight: bold; text-decoration-line: none;">hlchou@gmail.com</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
by loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<strong>“Good for you, you’ve decided to clean the elevator!”</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<strong>– The Elevator, from Dark Star</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android 預設的安全機制是透過Linux User-Authentication Security Control,基於使用者帳號與群組管理,提供每個應用程式單一帳號的管理機制. 這機制又稱為DAC (Discretionary access control, 隨意存取控制),所倚靠的就是使用者帳號/群組(ID/Group)的密碼認證稽核,基於此,Linux也是一個供Multi-User使用的環境.但如果有一個應用程式得到Linux系統的Root權限,就有能力沒有限制的存取與竄改系統資料,造成安全問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
新版的Android將提供Multi-User的操作環境,也就是說一個Android 裝置將有機會被一個以上的使用者登入使用,這情景可能是一個家庭共用的Android 平板電腦,或其它可能基於Android 開發出來的Multi-User裝置. 但同樣的,Android裝置被Root後,獲取本機應用最高執行權,就可存取其他使用者的資料,直接讀寫儲存裝置的Raw Block,或植入惡意程式偷取Multi-User資料.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要解決這問題,原本Linux Kernel DAC機制需要加以強化,而Android 4.3加入的SELinux也是其中最適當的方案,就算使用者在以Linux DAC保護下,取得Root權限,但基於SELinux的Policy,卻能限制Root使用者程式能操作的範圍,並保護Multi-User操作下其他使用者的資料安全問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SELinux 對Security Policy是採取白名單 (Whitelist)的策略,也就是說只有被同意的行為才能夠被允許.當開發商為新增的裝置,開發新的功能,就會有需求要不要新增Security Policy,用以確保新的行為正確無誤.Android本身,Android也接受開發商提交對其它開發商也有幫助的Security Policy改動 (http://source.android.com/source/submit-patches.html), 用以作為長期維護的方案.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
雖然,最新的Linux Kernel版本已經演進到3.10,且這版本的Linux Kernel也即將成為下一代的Long-Term Support Kernel,但目前Android Kernel最活躍的主線,還是Android 3.4.(<a href="https://android.googlesource.com/kernel/common/+/android-3.4" style="color: #666666; font-weight: bold; text-decoration-line: none;">https://android.googlesource.com/kernel/common/+/android-3.4</a>).,為了便於訊息的一致性,本文所查核的Linux Kernel Source Code會以筆者使用的3.4.58 Kernel為主.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
同樣的,本文在撰寫過程一定會盡力查證相關資訊,但若仍不免有所缺失,還請見諒. 希望本文能對同樣熱愛技術的開發者,有所助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android 4.3 + SELinux Kernel Source Code</strong><strong>的取得</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先下載最新的repo程式,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/repo</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並執行如下命令</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
~/repo init -u <a href="https://android.googlesource.com/platform/manifest%20-b%20android-4.3_r2.1" style="color: #666666; font-weight: bold; text-decoration-line: none;">https://android.googlesource.com/platform/manifest -b android-4.3_r2.1</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
~/repo sync</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就可以取得Android 4.3 的Source Code.有關Linux Kernel部分,建議是下載最新的Android 3.4 Kernel,但若你的開發環境為x86 Emulator的話,筆者透過SDK升級後,Android SDK內置開發環境還是使用2.6.39 Kernel 版本,使用SELinux上會有困難,若你需要在這環境驗證Android 4.3 + SELinux,則可以透過如下指令下載最新的GoldFish 3.4 Kernel Source Code</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
git clone https://android.googlesource.com/kernel/goldfish</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
git checkout –track -b android-goldfish-3.4 origin/android-goldfish-3.4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並透過如下編譯流程</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
make goldfish_armv7_defconfig</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
make zImage</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就可取得能在Android x86模擬器上執行的zImage (請自行rename到你的x86 Android-18模擬器環境中的kernel-qemu.), 如此即可透過x86模擬器驗證Android 4.3 + SELinux的環境.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android 4.3 Security</strong><strong>新增項目</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要了解Android 4.3 Security的變動,最佳參考資料就是Google的 “Security Enhancements in Android 4.3” 網頁(<a href="http://source.android.com/devices/tech/security/enhancements43.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://source.android.com/devices/tech/security/enhancements43.html</a>). 不過網頁上所例舉的項目,有些其實在Android 4.3之前就已經包括(可參考筆者另一篇拙作 <strong><span style="text-decoration-line: underline;">”Android 4.1 Jelly Bean</span></strong><strong><span style="text-decoration-line: underline;">安全機制探討” </span></strong>(<a href="http://loda.hala01.com/2012/08/android-4-1-jelly-bean%E5%AE%89%E5%85%A8%E6%A9%9F%E5%88%B6%E6%8E%A2%E8%A8%8E-2/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://loda.hala01.com/2012/08/android-4-1-jelly-bean%E5%AE%89%E5%85%A8%E6%A9%9F%E5%88%B6%E6%8E%A2%E8%A8%8E-2/</a>),或筆者認為應該跟其它項目結合在一起討論比較適合,就會先以自己的分類來做說明.開發者可根據自己的需求,自行進一步探索.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過下表讓我們把Android 4.3的Security項目做一個分類後的快速檢視</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 698px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164"><strong>安全改進項目</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="533"><strong>說明</strong></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164">透過SELinux強化Android sandbox</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="533">目前Linux Kernel支援多種LSM(Linux Security Modules)模塊,像是AppArmor,SELinux,Smack 與 Tomoyo, Android 4.3選擇的是最被廣為應用的SELinux. 這是一個基於 MAC(Mandatory Access Control)強制存取控制的安全機制 為了避免對應用程式的影響,Enforcing Mode將不會被開啟,而只會維持在Permissive Mode的狀態,以避免有些違反SELinux原則的應用因為開啟這機制後而有預期外的執行結果.但因為是基於Permissive Mode,所以雖然應用程式還是可以執行,但Kernel Log會打印出SELinux AVC(Access Vector Cache)的訊息,可供系統開發者透過Log,<span style="font-size: 11px; line-height: 19px;">查核系統中SELinux違例的狀況.</span></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164">限制具備SUID/SGID bit (setuid/setgid)能力的程式檔案</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="533">Linux 檔案系統支援SUID/SGID bits,會讓應用程式在執行時,有機會藉此讓Effective User-ID成為檔案擁有者的權限(“例如該檔案擁有者為root”),若程式本身沒有做好稽核的行為,就會因此開出一個後門導致root權限被取得. 為了防堵這類問題, Android原本就對/data與/cache檔案系統mount時設定”nosuid”,以防止這類情況發生. 新版Android除了盡可能移除具備SUID/SGID bits的程式檔案外,筆者驗證的 /system檔案系統其實也尚未去除nosuid,或許再來的改版會有機會看到Android 4.3把/system檔案系統用nosuid 進行mount,以避免來自Zygote/或衍生的Java APP Process執行SUID程式,導致root權限攻擊的風險.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164">ADB RSA Authentication.</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="533">支持ADB在跟電腦連接時,透過RSA Key進行認證機制. 用以避免入侵者透過電腦以未經授權的ADB連線進入Android手機裝置.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAXEzgeL2DT1ZQeEjp3Vfsci1Tr5l4NVSmkXp0wKKsC6SBujtCgeh-7i1DyGCEJhWJbNecpEmCTNMH20Lfqb62D8uEi-EtKEmx2AIi0lw8RTzNMgWQKik3_9b7KEKWLADUITcvWAsccaY/s1600/adb_rsa%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="218" data-original-width="229" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAXEzgeL2DT1ZQeEjp3Vfsci1Tr5l4NVSmkXp0wKKsC6SBujtCgeh-7i1DyGCEJhWJbNecpEmCTNMH20Lfqb62D8uEi-EtKEmx2AIi0lw8RTzNMgWQKik3_9b7KEKWLADUITcvWAsccaY/s1600/adb_rsa%255B1%255D.png" /></a></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164">限制Android Process Capability的繼承關係</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="533">在Android 4.3中,導入Linux Kernel 的PR_CAPBSET_DROP屬性,用以在產生新的Process時,透過Kernel把屬於特權等級的Capability給過濾掉,以避免可能存在的安全問題.像是在1, Dalvik VM中,會透過函式forkAndSpecializeCommon(in dalvik/vm/native/dalvik_system_Zygote.cpp)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在要fork出新的Process時,若使用者不為Root,會透過PR_SET_KEEPCAPS設置,以讓當新的Process 改變UID時,所被賦與的權限不被清掉.並透過PR_CAPBSET_READ,從0開始逐一確認Kernel賦與該Process特權的Bit(定義在 include/linux/capability)是否有被設定,若是則透過PR_CAPBSET_DROP逐一的清除掉.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,在ADB執行時,會透過函式should_drop_privileges(in system/core/adb/adb.c)確認ADB是否要以root權限執行,若非要以root權限執行,就會藉由函式drop_capabilities_bounding_set_if_needed(in system/core/adb/adb.c),除了保留CAP_SETUID與CAP_SETGID bits為,其它的Kernel被賦與的額外權限都會被清除掉.</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164">KeyChain支援查核isBoundKeyAlgorithm</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="533">透過KeyChain提供isBoundKeyAlgorithm(in frameworks/base/keystore/java/android/security/KeyChain.java),查核裝置的KeyStore是否有設定 KEYMASTER_SOFTWARE_ONLY,若無則表示這裝置支援透過Hardware儲存,並能保護System-wide Key不被Export出去的能力.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164">支援與強化記憶體溢位查核FORTIFY_SOURCE功能</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="533">透過致能FORTIFY_SOURCE能在 “bionic/libc/bionic/” 目錄下支援<span style="font-size: 11px; line-height: 19px;">__fgets_chk,__stack_chk_fail,__strlcpy_chk,__umask_chk,</span>__memcpy_chk,__strcat_chk,__strlen_chk,__vsnprintf_chk,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__memmove_chk,__strcpy_chk,__strncat_chk,__vsprintf_chk,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__memset_chk,__strlcat_chk,__strncpy_chk 這些函式,用以查核記憶體是否溢位.目前Android 4.3已在ARM/x86/MIPS的平台上開啟. (設定-D_FORTIFY_SOURCE=1)</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164">改善EntropyMixer</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="533">在EntropyMixer函式(in frameworks/base/services/java/com/android/server/EntropyMixer.java),<span style="font-size: 11px; line-height: 19px;">透過mBroadcastReceiver支援接收系統發出的ACTION_SHUTDOWN,ACTION_POWER_CONNECTED與ACTION_REBOOT Event,並在收到上述Event時,執行函式writeEntropy.並跟原有的writeEntropy一起搭配,用以確保Entropy結果被妥善保存,以便在系統重啟時提供給立即有需求的裝置使用.</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>UID/EUID((Effective User ID) </strong><strong>與</strong><strong> GID/EGID((Effective Group ID)</strong><strong>的概念</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如前述介紹,考量進一步的安全保護需求,Android會限制Filesystem與檔案SUID/SGID的配置. 因此我們針對這部份的主題,先做一個簡要的介紹,以便讓各位可以清楚SUID/SGID對系統的影響為何.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux的chmod指令除了可以設定檔案或目錄的<strong><span style="text-decoration-line: underline;">“Owner(rwx):Group(rwx):Others(rwx)”</span></strong>權限外,其實每個檔案都還包括了 “SUID:SGID:SBIT” 這三個 Bits,簡要敘述如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 738px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><strong>Bit</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><strong>Name</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="578"><strong>Note</strong></td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><strong>2</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80">SUID</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="578">Set User-ID<br />會讓執行這檔案的使用者,在這檔案執行過程中Process的Effective User-ID會變成這檔案的擁有者,並擁有同樣的User權限.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><strong>1</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80">SGID</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="578">Set Group-ID<br />會讓執行這檔案的Group群組,在這檔案執行過程中Process的Effective Group-ID會變成這檔案的擁有Group群組,並擁有同樣的Group權限.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80">SBIT</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="578">Sticky Bit<br />這功能只對檔案目錄有意義,設定這個Bit後,就只有本機Root或是目錄擁有者可以刪除該目錄.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過SUID/SGID我們就可以在特定的應用流程,讓執行該檔案的使用者可以有機會把User ID或Group ID切換為檔案的擁有者 User ID/Group ID.藉此達成特定的目的.最經典的例子應該就是 su與sudo這兩個指令,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[hlchou@www ~]$ ls -l /bin/su</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwsr-xr-x. 1 root root 32488 May 30 2011 /bin/su</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[hlchou@www ~]$ ls -l /usr/bin/sudo</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
—s–x–x. 2 root root 186768 Nov 12 2010 /usr/bin/sudo</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因為這兩個指令的執行檔案有設定SUID,所以當使用者執行這兩個程式時,就會以 Root 作為當下的Effective UID (也就是具備Root權限的能力),而這兩個程序只要確保沒有”Bug”,在執行過程中也有正確的稽核使用者輸入的密碼,就可以在考慮到基本安全的前提下認證使用者的密碼無誤後,才讓使用者可以切換為指定的使用者帳號(su)或是用Root權限去執行所要執行的應用程式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來筆者就用 SUID/SGID設定的例子,來示範操作Set UID/Set GID的Linux流程. 參考如下的test.c範例程式</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Current UID:%d EUID:%d \n”,getuid(),geteuid());</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Current GID:%d EGID:%d \n”,getgid(),getegid());</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
先以root權限編譯後,設定 711讓其他使用者也可以執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www hlchou]# gcc test.c -o test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www hlchou]# chmod 711 test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www hlchou]# ls -l test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwx–x–x. 1 root root 6731 Aug 11 07:55 test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當以一般使用者帳號執行時,可以看到UID/EUID都是屬於該使用者的對應ID</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[hlchou@www ~]$ ./test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Current UID:503 EUID:503</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Current GID:504 EGID:504</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果設定 SUID bit,在執行這應用程式的過程讓seteuid的流程發生,操作如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www hlchou]# chmod 4711 test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www hlchou]# ls -l test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rws–x–x. 1 root root 6731 Aug 11 07:55 test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們在以剛才一般使用者帳號,重新執行一次 test 執行檔,就可以看到UID/EUID執行結果如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[hlchou@www ~]$ ./test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Current UID:503 EUID:0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Current GID:504 EGID:504</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也就是執行者的UID=503, 但因為該檔案有SUID Bit,所以EUID最後會是root的UID=0,也因此這個Process就會以Linux DAC root權限來執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,當也設定 SGID時</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www hlchou]# chmod 6711 test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www hlchou]# ls -l test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rws–s–x. 1 root root 7060 Aug 11 08:24 test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
轉換到非Root帳號執行後,會發現不只是EUID變成root,連執行當下有效的EGID都會變成root所屬的Group.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www hlchou]# su hlchou</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[hlchou@www ~]$ ./test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Current UID:503 EUID:0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Current GID:504 EGID:0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
把最基礎的SUID/SGID問題做說明後,再來就以Linux提供的LSM Plug-in為標的進一步加以解析.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Linux Security Modules</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel支援Security Plug-in的LSM(Linux Security Modules)機制,用以讓希望在Kernel加入Security稽核的產品,可以有一個標準化的作法,而不是每個Security模塊各自根據自己的需求在Linux Kernel Source Code去安插查核點的代碼,並衍生後續維護上的困難.如下,為目前Linux Kernel支援LSM模塊的示意圖</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQze8_jnHHUGNxDIrfjAoWtb8pa3wzMnDPnD58b2SJNqb9MGAbSk4Z1zpntNPyxAXikHJJ5N2e4aJiRceDMhuCCbnyA-24i7u6nwumakwGBei8I-BMXluLmPcBTRRg9e35nFRUTzM9r5Q/s1600/image0011%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="498" data-original-width="634" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQze8_jnHHUGNxDIrfjAoWtb8pa3wzMnDPnD58b2SJNqb9MGAbSk4Z1zpntNPyxAXikHJJ5N2e4aJiRceDMhuCCbnyA-24i7u6nwumakwGBei8I-BMXluLmPcBTRRg9e35nFRUTzM9r5Q/s1600/image0011%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
查核2.6 Kernel Source Code,最早被納入LSM的模塊為美國國家安全局NSA(National Security Agency, http://www.nsa.gov/research/selinux/)所開發的SELinux架構.(筆者能查到的日期/版本為2003年Linux kernel 2.6.0-test3) 概念為以類似燒瓶的安全架構(Flask security architecture),基於MAC(mandatory access control)針對不同的Role/Domain/Object提供彈性的強制存取管控安全需求.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
隨後,到了2.6.25 Kernel,由Casey Schaufler所開發的Smack(Simplied Mandatory Access Control Kernel)也被納入,作為另一套LSM的選擇,參考作者的Paper “Smack in Embedded Computing” (from<a href="http://ols.fedoraproject.org/OLS/Reprints-2008/schaufler-reprint.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://ols.fedoraproject.org/OLS/Reprints-2008/schaufler-reprint.pdf</a>),主要透過最長23個字元以Null結尾的字串來表示Label, 每一個Task對Object的存取都必需要跟Label定義的稽核機制吻合才能放行,這方案設計主要應用在Embedded System的安全需求,已知像是MeeGo,WindRiver..etc都有相關產品應用.目前的官網為 <a href="http://schaufler-ca.com/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://schaufler-ca.com/</a>.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
之後,在2.6.30 Kernel 加入了由日本NTT Data Corporation所開發的TOMOYO,作為新的LSM成員,最早加入Linux 主線的版本為TOMOYO Linux 2.2 (最新版本則為TOMOYO Linux 2.5),這是一套以Pathname為基礎的Security稽核機制,有一篇在LWN的文章 “TOMOYO Linux and pathname-based security” (in <a href="http://lwn.net/Articles/277833/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://lwn.net/Articles/277833/</a>),可供有興趣的開發者參考,目前的官網為<a href="http://tomoyo.sourceforge.jp/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://tomoyo.sourceforge.jp/</a> .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
到了2.6.36 Kernel,則加入了由Immunix開發的AppArmor(Application Armor),並由Novell支持至2007年後終止,這也是一套以Pathname為基礎的Security稽核機制,跟SELinux最大的不同在於,SELinux識別FileSystem Object是以inode的編號為主,因此就算同一個檔案產生兩個不同的Hard Link,都還是可以透過SELinux識別出正確的Security Object參數.但AppArmor是以File Path為識別的基礎,因此在AppArmor下,只要把檔案Hard Link到不同的路徑就可以避開稽核.由於Linux本身就包含了Path-based 與 Inode-based 的存取控制,只要使用者檔案權限有正確設定,就還是能夠涵蓋這部份的安全操作. (例如設定為chmod 700的檔案就算Hard Link還是會繼承前者的700權限設定),目前AppArmor的官網為<a href="http://wiki.apparmor.net/index.php/Main_Page" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://wiki.apparmor.net/index.php/Main_Page</a>.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
到了3.4 Kernel,則新增了Yama, 作者為Chromium OS的開發者 Kees, Yama 是一個基於LSM機制用來強化Linux DAC的安全機制,本身並非如前述LSM模塊,要成為功能完整的Security Module,而只針對現有DAC要強化的部份進行補強.像是改善ptrace的安全問題,傳統上,使用者可以藉由GDB呼叫ptrace去執行一個要被Attach的Process,或具有Root權限的使用者,也可以透過ptrace去Attach想要抓取記憶體資料的Process,基於Yama LSM,在透過<strong><span style="text-decoration-line: underline;">“/proc/sys/kernel/yama/ptrace_scope”</span></strong>設定為Mode 1<strong><span style="text-decoration-line: underline;"> “restricted ptrace”</span></strong>時,則需先藉由PR_SET_PTRACER設定能被ptrace Attach的Process關係,才能讓ptrace Attach發揮作用,藉此強化DAC環境的安全. 有關Yama的進一步資訊,可參考Linux Kernel Soruce Code中的文件 “Documentation/security/Yama.txt”.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來就是從LSM代碼進行查核,但由於這並非本文主要的議題,會盡量簡要的說明,有興趣的開發者還請自行參閱Linux Kernel Source Code.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>LSM </strong><strong>的進一步探究</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Security Modules (LSM) Source Code位於 security目錄下,每個想在Linux Kernel實現 Linux Security Modules的Securuity機制都可以透過函式 register_security (in security/security.c),註冊屬於自己的Linux Security Modules (LSM)機制,由於LSM已經在Kernel關鍵的位置都埋好Security查核的點,因此要支援LSM的開發者,只需要透過函式 register_security 註冊 struct security_operations *security_ops (in include/linux/security.h),就可以讓Linux Kernel在運作時,主動在關鍵的查核點呼叫所提供的Callback函式,確認當下Security稽核的狀況. 有關struct security_operations 的定義可以參考線上Source Code “http://hala01.com/src/linux/linux-3.4.58/HTML/S/3591.html#L1381″.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
談完了LSM,再來就該鎖定Android 4.3最大的改動SELinux來做說明.其實只要Google一下就會發現深入介紹SELinux的技術文章非常多,既然這是一個成熟也被廣泛使用的技術,重新撰寫同樣的文章其實幫助有限,接下來對SELinux的簡述,會以概要的方式帶過這體系的演進,有關SELinux技術與實際的操作,還請自行參閱網路上的文件.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>SElinux</strong><strong>緣起</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SELinux是在2003年的Linux Kernel 2.6之後納入到Linux Kernel的範疇中,最早的發想是來自於美國國家安全局NSA(National Security Agency).參考美國國家安全局(NSA)的網頁(http://www.nsa.gov/research/selinux/),SELinux是採用類似燒瓶的安全架構(Flask security architecture),用以提供多樣的強制存取管控,可針對包括存取的類型/角色/不同等級的安全需求. 如下圖所示,使用者登入後會被賦與對應的Role,再根據應用的場景會被轉移到不同的Domain中,而不同的Domain就會具備不同層級的安全存取權限.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH-39JGRBs1iwT1FJKy1WtcLSP9UMvIgsAE-PsFQdBZfrtTh4G5vP0o3_rEjoOYZQTjMKjqvfmxBi8qvTOrDeiEs02RhalhtYlFjZ-VeNyEPYX8yJMByStaF71J_6KDp1DCsERnuWTL14/s1600/image0021%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="492" data-original-width="692" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH-39JGRBs1iwT1FJKy1WtcLSP9UMvIgsAE-PsFQdBZfrtTh4G5vP0o3_rEjoOYZQTjMKjqvfmxBi8qvTOrDeiEs02RhalhtYlFjZ-VeNyEPYX8yJMByStaF71J_6KDp1DCsERnuWTL14/s1600/image0021%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">支援Security-enhanced Linux kernel的核心,會基於MAC(mandatory access control)原則,限制使用者程序或服務擁有最小能運作的權限,因為是基於這樣嚴格受限的權限管控概念,當使用者的程式或服務因為緩衝區溢位(Buffer Overflow),或一些設計上的錯誤導致安全問題發生時,就可以把損害降到可控的範圍.相對於原本Linux Kernel基於使用者的帳號/群組的概念,SELinux並沒有所謂的Root使用者(也就是Super-User)的概念,也不需透過setuid/setgid來規範使用者/群組的權限,它是一個獨立於傳統Linux Access Control的機制.傳統的Linux Kernel會仰賴系統管理者有正確的設定應用程式帳號權限,與保護好重要帳號權限的安全問題,一旦特權等級使用者的帳號被破壞,那整個系統的傷害也就不容小覷.而SELinux是基於對Kernel與Security Policy正確設定來施行保護,當應用程式發生安全問題時,則能把損害範圍限制在個別使用者的應用程式或系統服務範圍中.可避免因為其它應用程式的安全問題而讓整個系統受到安全威脅.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIBYWkYIyEB-dinf7_s4Jwu4uhGhP6H7n2Pbqw-MfniYpm_SmVrxHPFfU1f5BkFXH98ZYDT6twHKbOu4CHCfwfJD0D_3P-VqUDlNt3C_OGuC0zuoXiEpTsmS_SXZE1IRrj8SiWrwH3Okg/s1600/image0031%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="260" data-original-width="692" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIBYWkYIyEB-dinf7_s4Jwu4uhGhP6H7n2Pbqw-MfniYpm_SmVrxHPFfU1f5BkFXH98ZYDT6twHKbOu4CHCfwfJD0D_3P-VqUDlNt3C_OGuC0zuoXiEpTsmS_SXZE1IRrj8SiWrwH3Okg/s1600/image0031%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SELinux設計用來防範應用程式資料被其他程序讀取或是竄改,或藉漏洞跳過安全稽核的檢查,執行不被信賴的應用程式,透過違反系統安全原則(Security Policy)干擾其他應用程式. SELinux 的實做包括 LSM 與 MSL for Sensitivity Levels and Categories 兩部份, SELinux預設的MLS (Multi-Level Security)數值起點為 s0,數值越大表示安全要求的Sensitivity Level越高,而Security Category表示所屬Security Level對應的分類 (若不設定,預設為 c0),不同的Categories就算是屬於同一個Sensitivity Level,也是不能Access對應的物件. 原因在於MLS是把同一個Sensitivity Level,但不同的Categories 視為兩個不同的Sensitivity Level來源,因此會認為這兩個不同來源的Access,應該分屬兩個不同的群體,因而不具備另一方的Access權限.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android SELinux</strong><strong>解析</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android 4.3中,SELinux Security Policy制定的檔案主要存放在Android 4.3 Source Code “external/sepolicy/” 目錄下,並提供以下三個命令供SELinux使用上查核</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,</strong>/system/bin/getenforce:可用以查核系統支援SELinux的狀況,像是</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">root@generic:/ # getenforce<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Permissive è表示SELinux示在Permissive Mode</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
root@generic:/ # getenforce</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Enforcing è表示SELinux示在Permissive Mode</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
root@generic:/ # getenforce</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Disabledè當下組態,並不支援SELinux <strong>(</strong><strong>通常是Linux Kernel </strong><strong>沒有被設定正確)</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,</strong>/system/bin/setenforce:用以在有支援SELinux的環境,決定要使用Enforcing或Permissive Mode.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">sroot@generic:/ # etenforce<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3,</strong> /system/bin/sepolicy:用以載入指定位置的SELinux Policy二進位檔案</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">127|root@generic:/ # load_policy<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
usage: load_policy policy-file</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1|root@generic:/ # load_policy /sepolicy</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
load_policy /sepolicy</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ANDROID 4.3 + SELinux的環境,因為採用白名單的概念,只有關於系統安全/應用必需的選項,才會致能,基本的概念就是最小特權開放的原則 (Principle of least privilege, http://en.wikipedia.org/wiki/Principle_of_least_privilege).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android SELinux文件中提供了以下Use Case作為範例,用以說明SELinux Policy.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1, Symlinks</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Linux的環境中,Symbol Link會以檔案的方式存在,這可能會帶來一些問題. 例如,init程式會在初始化的過程中去改變檔案的權限,若駭客透過Symbol Link產生檔案,並用自己的帶有惡意代碼的檔案置換.就有機會產生安全上的風險. 對SELinux來說,若我們已經很明確的知道自己的程式一定不會去Access透過 Symbol Link產生的檔案,就可以透過SELinux Policy來禁止這樣的行為.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2, System files</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過SELinux,可以定義一類(Class)的檔案為System Server才會存取的檔案,就算其它行程是以Root身分所執行的,也都不能存取這些檔案.除非這些行程能把自己切換到System Server執行的Domain.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3, APP Data</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在實際應用上,如果有行程必需要具備Root權限才能達成任務.而這個行程又不需具備去存取網路應用有關程式的資料.只要不把這行程加入白名單中,就可確保這部份資料的安全無虞.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>4, setattr</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可透過把檔案區分為 APP/Shell/System…etc(app_data_files,shell_data_files and system_data_files).用以限定像是透過 chmod/chown這類會改變檔案Attributes的指令只能在App Data類的檔案有作用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來就是針對Android SELinux的相關設定與配置加以說明,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,SELinux policy source (*.te) </strong><strong>檔案路徑</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
針對整個Android SELinux通用的 Policy 檔案路徑為 external/sepolicy</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
針對特定裝置的 SELinux Policy檔案路徑為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
device/asus/grouper/sepolicy</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
device/lge/mako/sepolicy</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
device/samsung/manta/sepolicy</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
device/samsung/tuna/sepolicy</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
針對特定產品的Security Policy檔案,建議放在對應裝置的路徑中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,</strong><strong>修改 BoradConfig.mk</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可透過 device目錄下,看到如下產品的參考設定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
./device/asus/grouper/BoardConfig.mk</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
./device/lge/mako/BoardConfig.mk</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
./device/samsung/manta/BoardConfig.mk</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
./device/samsung/tuna/BoardConfig.mk</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關BoardConfig.mk跟SELinux Policy設定有關的變數說明,可以參考如下表的簡述.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 651px;"><tbody>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="651"><strong>SELinux Policy Generation Variables in BoardConfig.mk</strong><strong>以Ausu Grouper產品為例,路徑在device/asus/grouper/BoardConfig.mk</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><strong>Name</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433"><strong>Note</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217">BOARD_SEPOLICY_REPLACE</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">用以取代/置換原本放在 external/sepolicy 屬於跟Device無關的Policy定義檔案. 如果所指定要置換的檔案並不存在 external/sepolicy 目錄下,則會產生錯誤.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217">BOARD_SEPOLICY_UNION</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">用以作為原本放在external/sepolicy目錄下Policy定義檔案的擴充,會跟同名的檔案做聯集,成為一個包括Android原本Policy定義與也包括特定裝置客製化Policy定義的內容.<br />以Ausu Grouper產品為例,<br />BOARD_SEPOLICY_UNION := \<br />file_contexts \<br />genfs_contexts \<br />app.te \<br />btmacreader.te \<br />compatibility.te \<br />device.te \<br />drmserver.te \<br />init_shell.te \<br />file.te \<br />rild.te \<br />sensors_config.te \<br />shell.te \<br />surfaceflinger.te \<br />system.te \<br />zygote.te</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217">BOARD_SEPOLICY_DIRS</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">用以指向存有供特定裝置的BOARD_SEPOLICY_UNION 與BOARD_SEPOLICY_REPLACE 使用的Policy檔案目錄路徑.<br />(編譯後,可參考路徑out/target/product/<device>/etc/sepolicy_intermediates/policy.conf).<br />參考上述的說明,如果同一個檔案同時被BOARD_SEPOLICY_UNION 與 BOARD_SEPOLICY_REPLACE所包括,則會產生錯誤.<br />以Ausu Grouper產品為例,<br />BOARD_SEPOLICY_DIRS := \<br />device/asus/grouper/sepolicy</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217">BOARD_SEPOLICY_IGNORE</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="433">如果有指定目錄下的Policy檔案是這個裝置所不希望納入的,則可在這變數中加入.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,修改 file_contexts,加入要納入Policy的檔案,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如路徑 device/asus/grouper/sepolicy/file_contexts,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
開發者只需加入要納入Policy的檔案,重新編譯,以便讓新增的檔案/Policy發揮作用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一個Android SELinux的 Policy檔案主要包括三個部份</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,Allow: 把對目標 Context 執行操作的權限, 交給指定的Domain.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,Domain: 定義Policy指定的Domain範圍,對Kernel而言會對應到一個SID (Security Identifier).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Context: 定義該Policy Rule的內容, 對Kernel而言,會對應到一個 Rule ID (Identitier),已供識別</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因此一個完整的Policy描述會像是如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>“allow appdomain app_data_file:file rw_file_perms;”</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,ALLow: allow</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,Domain: appdomain</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Context: app_data_file:file rw_file_perms</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這個Policy Rule用來表示, 屬於Domain Appdomain的應用程式,被允許可以讀寫有被標籤屬於 “app_data_file” 的應用程式檔案.在編譯過程後,這就會成為SELinux Policy新增的一部分.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
關於Android SELinux Class的定義, 參考 Android external/sepolicy/access_vectors, external/sepolicy/security_classes 與 Linux Kernel security/selinux/include/classmap.h檔案,可以看到Android/SELinux會把系統行為分類為幾大類的Class,主要包括 File,Socket,IPC,Userspace Database Object,Pointer and Keyboard這幾大類,如下表格所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 610px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171"><strong>Class Categories</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439"><strong>Class Name</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">File-related objects</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">Filesystem,Dir,File,lnk_file,<br />chr_file,blk_file,sock_file,fifo_file,fd.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Network-related objects</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">Socket,tcp_socket,udp_socket,rawip_socket,<br />node,netif,netlink_socket,packet_socket,<br />key_socket,unix_stream_socket,unix_dgram_socket</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Process-related objects</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">process</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Ipc-related objects</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">IPC, sem, msgq , msg, shm</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Security server</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">security</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">System operations</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">system</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Controling capabilies</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">capability,capability2</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Controlling changes to passwd information</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">passwd</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">SE-X Windows stuff</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">x_drawable, x_screen, x_gc, x_font, x_colormap, property,x_selection,x_cursor,x_client,x_device,<br />x_server,x_extension,x_resource,x_event,x_synthetic_event</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Extended Netlink classes</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">netlink_route_socket,netlink_firewall_socket,netlink_tcpdiag_socket,<br />netlink_nflog_socket,netlink_xfrm_socket,netlink_selinux_socket,<br />netlink_audit_socket,netlink_ip6fw_socket,netlink_dnrt_socket</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Controlling access and communication through the D-BUS messaging system</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">dbus</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Controlling access through the name service cache daemon (nscd)</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">nscd</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Controlling access to IPSec network data by association</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">association</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Updated Netlink class for KOBJECT_UEVENT family</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">netlink_kobject_uevent_socket</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">network peer labels</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">peer</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="171">Others</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="439">appletalk_socket,packet,key,context,dccp_socket,memprotect,<br />db_database,db_table,db_procedure,db_column,db_tuple,<br />db_blob,x_application_data,kernel_service,tun_socket,<br />x_pointer,x_keyboard,db_schema,db_view,db_sequence,<br />db_language,binder,zygote,property_service</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並會透過 File Contexts (in external/sepolicy/file_contexts) 設定對應路徑預設的SELinux檔案屬性.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>SELinux</strong><strong>的</strong><strong> Access vector cache (AVC) Kernel Log</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在有啟動SELinux的環境下,例如以筆者的Linux工作站為例,透過dmesg就可以看到有關SELinux作用下,的檢查機制訊息.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697"><strong>type=1400 audit(1376604216.234:41987): avc: denied { search } for pid=17022 comm=”sendmail” dev=sdb3 ino=59113482 scontext=system_u:system_r:h</strong><span style="font-size: 11px; font-weight: bold; line-height: 19px;">ttpd_t:s0 tcontext=system_u:object_r:postfix_spool_t:s0 tclass=dir</span>type=1400 audit(1376604216.273:41988): avc: denied { search } for pid=17023 comm=”sendmail” dev=sdb3 ino=59113482 scontext=system_u:system_r:h<span style="font-size: 11px; line-height: 19px;">ttpd_t:s0 tcontext=system_u:object_r:postfix_spool_t:s0 tclass=dir</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但如果你在目前版本的Android 4.3上,也希望可以查核到類似的SELinux AVC存取稽核錯誤訊息,會發現Kernel Log並找不到這些字串,原因除了目前預設為Permissive Mode外 (Permissive只是不禁止操作,但還是會打印違規的Log),最重要的是目前的Android 4.3 SELinux Policy支援了”unconfined_domain”的TE巨集,目前主要的Domain TE設定檔案,會把在定義Domain時也加上”unconfined_domain”巨集的設定,如此就會讓所有的SELinux Domain都成為毫無限制的Domain. 如果要實際驗證SELinux AVC的稽核結果,筆者的作法為修改檔案” external/sepolicy/te_macros”中的</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">#####################################<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# unconfined_domain(domain)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# Allow the specified domain to do anything.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define(`unconfined_domain’, `</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
typeattribute $1 mlstrustedsubject;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
typeattribute $1 unconfineddomain;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
‘)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
改為</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">#####################################<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# unconfined_domain(domain)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# Allow the specified domain to do anything.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define(`unconfined_domain’, `</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#typeattribute $1 mlstrustedsubject;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#typeattribute $1 unconfineddomain;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
‘)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
刻意讓”unconfined_domain”巨集內容為空,重新編譯後,就可以看到你的Android 4.3 SELinux AVC Kernel Log在打印相關的違例訊息了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Android 4.3裝置上,就可透過dmesg指令,查詢有avc 字串的SELinux Kernel Log了. (或透過adb shell dmesg | grep avc). 筆者摘要Android 4.3上SELinux AVC Kernel Log內容如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697"><strong><5>[ 2057.468752] (1)[237:adbd]type=1400 audit(1357001068.255:4584): avc: denied { open } for pid=237 comm=”adbd” path=”/dev/ptmx” dev=”tmpfs” ino=3147 scontext=u:r:adbd:s0 tcontext=u:object_r:ptmx_device:s0 tclass=chr_file</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><5>[ 2057.472129] (1)[237:adbd]type=1400 audit(1357001068.255:4585): avc: denied { ioctl } for pid=237 comm=”adbd” path=”/dev/ptmx” dev=”tmpfs” ino=3147 scontext=u:r:adbd:s0 tcontext=u:object_r:ptmx_device:s0 tclass=chr_file</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><5>[ 2057.474762] (1)[237:adbd]type=1400 audit(1357001068.255:4586): avc: denied { fork } for pid=237 comm=”adbd” scontext=u:r:adbd:s0 tcontext=u:r:adbd:s0 tclass=process</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><5>[ 2065.183385] (1)[5459:ps]type=1400 audit(1357001075.965:4607): avc: denied { getattr } for pid=5459 comm=”ps” path=”/proc/3796″ dev=”proc” ino=16450 scontext=u:r:init_shell:s0 tcontext=u:r:shell:s0 tclass=dir</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><5>[ 2065.185931] (1)[5459:ps]type=1400 audit(1357001075.965:4608): avc: denied { search } for pid=5459 comm=”ps” dev=”proc” ino=16450 scontext=u:r:init_shell:s0 tcontext=u:r:shell:s0 tclass=dir</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><5>[ 2065.189092] (1)[5459:ps]type=1400 audit(1357001075.975:4609): avc: denied { read } for pid=5459 comm=”ps” dev=”proc” ino=15703 scontext=u:r:init_shell:s0 tcontext=u:r:shell:s0 tclass=dir</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><5>[ 2065.191501] (1)[5459:ps]type=1400 audit(1357001075.975:4610): avc: denied { open } for pid=5459 comm=”ps” path=”/proc/3796/task” dev=”proc” ino=15703 scontext=u:r:init_shell:s0 tcontext=u:r:shell:s0 tclass=dir</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android SELinux Run-Time</strong><strong>的</strong><strong>ID/Process/</strong><strong>檔案配置</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來讓我們透過簡單的指令,查核Android 4.3下有關SELinux的環境與配置狀況.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先,可以透過 id –Z,查核使用者帳號與其Security配置</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 564px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="122"><strong>ID</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="442"><strong>id -Z for security info.</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="122"><strong>root</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="442">uid=0(root) gid=0(root) context=u:r:shell:s0</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="122"><strong>su to radio</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="442">uid=1001(radio) gid=1001(radio) context=u:r:su:s0</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="122"><strong>su to u0_a23</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="442">uid=10023(u0_a23) gid=10023(u0_a23) context=u:r:su:s0</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
查核Process Security配置,則可透過 ps –Z,簡要內容分類如下(根據不同的Domain區分Process)</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 402px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><strong>Domain name</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278"><strong>Reference process</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">kernel</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">kthreadd,ksoftirqd,kworker,<br />khelper,sync_supers,bdi-default,<br />kblockd,rpciod,kswapd,<br />fsnotify_mark,crypto,<br />mtdblock0,mtdblock,<br />binder, deferwq,ccc,flush</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/init</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">ueventd</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/sbin/ueventd</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">servicemanager</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/servicemanager</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">vold</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/vold</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">netd</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/netd</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">debuggerd</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/debuggerd</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">surfaceflinger</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/surfaceflinger</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">zygote</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">zygote</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">drmserver</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/drmserver</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">mediaserver</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/mediaserver</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">installd</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/installd</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">keystore</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/keystore</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">qemud</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/qemud</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">init_shell</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/sh</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">adbd</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/sbin/adbd</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">system</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">system_server</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">radio</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">com.android.phone</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">release_app</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">com.android.providers.calendar,<br />com.android.browser,<br />android.process.acore,<br />com.svox.pico,<br />com.android.email,<br />com.android.exchange</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">shared_app</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">com.android.launcher,<br />com.android.inputmethod.latin,<br />com.android.quicksearchbox</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">platform_app</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">com.android.systemui,<br />com.android.sharedstoragebackup,<br />com.android.defcontainer</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">untrusted_app</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">…etc</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">isolated_app</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">…etc</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">rild</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/rild</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">shell</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">/system/bin/sh,<br />ps,logcat</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123">su</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278">sh</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過 ls –Z,則可以查核每個檔案物件配置的Security屬性,同樣的根據File Type,Security與路徑簡要分類如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 541px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120"><strong>File Type</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><strong>Security Settings</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232"><strong>Reference Path</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">rootfs</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:rootfs:s0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/config<br />/init<br />/init.rc</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">cache_file</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:cache_file:s0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/cache</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">cgroup</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:cgroup:s0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/acct</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">proc</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:proc:s0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/proc</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">sysfs</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:sysfs:s0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/sys</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">unlabeled</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:unlabeled:s0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data/resource-cache<br />/data/security<br />/data/data<br />/data/data/com.android.shell</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">system_file</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:system_file:s0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">system</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">system_data_file</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:system_data_file:s0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data<br />/data/nativebenchmark<br />/data/nativetest<br />/data/data/com.android.settings</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">platform_app_data_file</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:platform_app_data_file:s0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data/data/com.android.providers.calendar<br />/data/data/com.android.providers.contacts<br />/data/data/com.android.providers.downloads</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">radio_data_file</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:radio_data_file:s0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data/data/com.android.providers.telephony</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">app_data_file</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:app_data_file:s0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data/data/com.android.widgetpreview<br />/data/data/com.example.android.apis<br />/data/data/com.example.android.livecubes<br />/data/data/com.example.android.softkeyboard</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">tombstone_data_file</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:tombstone_data_file:s0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data/tombstones</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">backup_data_file</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:backup_data_file:s0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data/backup</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">anr_data_file</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:anr_data_file:s0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data/anr</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120">apk_data_file</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189">u:object_r:apk_data_file:s0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="232">/data/app</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
總結上述系統的瀏覽狀況,我們可以從Role,Process,Domain與檔案Object的關係得到如下的示意圖,使用者必需要在具有權限Access的Domain中才可以去存取想要的物件. 就算是具備Root權限的使用者,如果沒有存取對應Object所需的安全配置,也會被禁止存取物件,藉此確保系統的安全性.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYBesi1ZzPar7Gl-1xht3GjIiZbke_Kx09wFZXsSxIaWojY-Tg0rdU3a_4-Absj1YpJL48LHgo5SdqM6yYyimsVIwo0bODcIOL-D66nBKZnLr6-gf5wAt-RIhGGK2L8pme8Ne538ZBF64/s1600/image0041%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="550" data-original-width="691" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYBesi1ZzPar7Gl-1xht3GjIiZbke_Kx09wFZXsSxIaWojY-Tg0rdU3a_4-Absj1YpJL48LHgo5SdqM6yYyimsVIwo0bODcIOL-D66nBKZnLr6-gf5wAt-RIhGGK2L8pme8Ne538ZBF64/s1600/image0041%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後,就是讓筆者碎碎念一下對於MLS/DAC/MAC這些機制差異的部份,除了讓自己長一些知識外,也希望對大家有幫助.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>MLS (Multi-Level Security)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
MLS是目前SELinux採用的MAC (Mandatory access control)前身,由美國軍方單位所推展,主要概念為把Subject/Object定義不同的安全等級,並管控資料從低安全等級向高安全等級傳遞,低安全等級只能對高安全等級的Object寫入資料,不能讀取.而高安全等級只能跟低安全等級的Object讀取資料而不能寫入.運作的概念如下圖所示.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP3-wwVO-RZ-U8BfZrtknCuql-QxpyODK9vW9xxHIBN5NpCmXRN8sf4kx3t0Qt59F45B4jr9xfr0p6QUyD63XhOJWzUNDnRBT7Bp8yQo3lL1ImmTViteQaM5hkN118MKVOzE3lStNyKq4/s1600/image0051%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="536" data-original-width="714" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP3-wwVO-RZ-U8BfZrtknCuql-QxpyODK9vW9xxHIBN5NpCmXRN8sf4kx3t0Qt59F45B4jr9xfr0p6QUyD63XhOJWzUNDnRBT7Bp8yQo3lL1ImmTViteQaM5hkN118MKVOzE3lStNyKq4/s1600/image0051%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但由於MLS是非常嚴格的限定資料的流向管控,但卻並不適用於所有的安全場景中,此外也並非所有High-Level Security等級的內容都與機密有關,因此需要一個有彈性,且基於Type的Access Control,用以實現安全管控的高度配置能力.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>隨意存取控制</strong><strong>DAC (Discretionary access control)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
DAC(Discretionary Access Control)是傳統Unix/Linux環境的安全管控機制,透過使用者帳號(Identity)或群組(Group)歸屬的方式,來限制控管物件的存取權限,相較於完全沒有安全管控的環境(也就是每個使用者都可以存取所有檔案資料的機制), DAC主要基於<strong><span style="text-decoration-line: underline;"> “Owner(rwx):Group(rwx):Others(rwx)” </span></strong>為概念 (如下所示),定義存取執行權限,用以提供最基本的保護措施.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt over"><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697"><strong>$ ls -l</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x. 1 root root 2458 May 20 2012 set-xcode-analyzer</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rw-r–r–. 1 root root 16917 May 20 2012 sorttable.js</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
drwxr-xr-x. 2 root root 4096 Jul 28 2012 spider</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如同前述UID/EUID的操作範例,一旦系統管理者的檔案設定了SUID,但又因為安全漏洞,導致這檔案本身的稽核流程疏失,而讓第三方的程式有機會藉此取得系統的Root權限,就會導致管控以外的重大安全漏洞.在傳統的Linux DAC機制下,我們可能因為一些系統設計上的需求,就把Root權限給了特定的使用者, 取得這權限的使用者,就有機會可以對Storage執行 Raw Block的寫入操作,進而有機會去竄改系統的設定,但在SELinux MAC保護下,雖然使用者具備Root權限,但因為MAC Policy並不允許直接對Storage Raw Block作寫入的操作, 也因此,這樣的操作就會被MAC Policy稽核的流程給擋下.進而確保系統的安全性.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>強制存取控制</strong><strong> MAC (Mandatory access control) –</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
MAC跟DAC的機制在定義上可說是相對的,因此查詢資料時,MAC又稱為 ”Non-Discretionary Access Control”. MAC (Mandatory access control) 指的是更嚴格的安全管理措施,針對像是Process/Thread所能使用的記憶體單元,檔案(Files),目錄(Directory),TCP/UDP Ports,進行管理的措施.當有一個Process/Thread要對這些資源進行存取的行為時,作業系統就會驗證兩者安全屬性(Security Attributes),是否符合才許可執行後續的動作.甚至,包括像是資料庫系統,也可以套用MAC管理機制,針對要存取資料庫Table/View/Procedures的Process/Thread進行安全管控.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考 Android 4.3 CCD (Compatibility Definition Document)文件 (http://source.android.com/compatibility/android-4.3-cdd.pdf),Android 4.3 Sandbox會基於SELinux MAC(Mandatory Access Control)提供安全保護措施.並讓安全機制與Framework的改動,是讓使用者,開發者與應用程式執行流程沒有差異,確保相容性問題,所提供的API也要避免可讓任一APP設定後而影響到其它APP的行為.因此,Android 4.3預設的 SELinux的行為是Permissive Mode (非強制開啟的Enforcing Mode),所有應用程式違例的操作只會顯示在透過dmesg查看的Kernel Log中,而不會讓應用程式真的因此而無法執行,或導致相關的正確性問題.並支援Dynamic Policy Update, 可以不用整個System Image都更新,只更新所需的Security Policy. Android 4.3 SELinux的Policy主要儲存在根目錄的 /sepolicy檔案中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在同時包括DAC+MAC的系統上 (也就是把Linux 中的SELinux打開的組合).我們可以把DAC看成是Linux 環境中原生就支援的基礎安全管理措施,MAC則是又把DAC的安全性,更進一步的強化,使用者具備的操作權限會如下圖一般被嚴格的限制住.(也更適用於Multi-User的執行環境).</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglSdUo-UiOL8VbXQyIURS4AlK3GixDcj-DLPrFmr5OKAQNhIlKUx7_sJwdiblWY29pxsEXldQHoPuxq6L-bwvAaN_iar3Ioi1ImmuFo8h06HtYg3vzxjy-COsht4z8hvcICX_UrwfD4es/s1600/image0061%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="319" data-original-width="692" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglSdUo-UiOL8VbXQyIURS4AlK3GixDcj-DLPrFmr5OKAQNhIlKUx7_sJwdiblWY29pxsEXldQHoPuxq6L-bwvAaN_iar3Ioi1ImmuFo8h06HtYg3vzxjy-COsht4z8hvcICX_UrwfD4es/s1600/image0061%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當前一版Android釋放出Multi-User的概念時,當下會覺得現在Android被Root的裝置滿普遍的,一旦又支援Multi-User,那使用者資料被竊取,或是資安問題肯定會比現在更多.但從這版Android 4.3來看,確實Android的安全性已經不同於我們過去的認知,也更具備保護Multi-User環境下的使用者資料能力.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
希望本文能對大家有所幫助,也感謝有這樣的Open Source環境,讓我們可以持續的長知識,又拓展自己的技術視野….<strong>Orz</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-59640919400536387302017-06-04T10:10:00.001-07:002017-06-04T10:10:28.180-07:00Android/Linux Kernel 記憶體管理-入門筆記<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android/Linux Kernel 記憶體管理-入門筆記</h1>
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android/Linux Kernel </strong><strong>記憶體管理</strong><strong>–</strong><strong>入門筆記</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<a href="mailto:hlchou@gmail.com" style="color: #666666; font-weight: bold; text-decoration-line: none;">hlchou@gmail.com</a><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<strong>by loda.chou</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這是一篇寫給自己看的筆記,牽涉的範圍是Android/Linux Kernel上下層的記憶體管理機制,由於牽涉到基礎,核心與使用者空間的Framework,這系列的文章會分為幾個單元,依據筆者自己的時間安排,逐一分享出來,並希望對各位有所助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
相對於整理Kernel 排程,FileSystem,與相關核心模組的知識,重新再去彙整Kernel記憶體機制的Topics,會發現表現上看似簡單的Malloc/Free,背後的諸多細節都有他不簡單的道理. 同時,所需供應的記憶體對象,還包括User-Space/Kernel-Space的應用需求,但考量到安全,記憶體的節省與效率,背後就會衍生出諸多設計去改善這些路徑,要能清楚的掌握,還須用功紮根才是. 雖然撰寫過程中盡可能確保資訊的完整與正確性,若仍有所不足還請見諒.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文會以Linux Kernel 3.5.4為參考Source Code,目前Kernel已經演進到3.6.1 (http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.6.1.tar.bz2),Kernel Memory也有一些改善,後續的討論也會轉到3.6核心上,若各位手中的Kernel邏輯與筆者所參照有落差,請以自己手中所使用的Linux Kernel版本Source Code為主.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在軟體的世界,處理器需要記憶體上儲存的指令集與資料來運算開發者所設計好的邏輯,從一個Task的產生,就會涉及 Data/Code Segment Memory Mapping,Stack與Heap的Memory Allocation. 在non-MMU的世界,包括作業系統與應用程式都直接面對實體記憶體,在這階段的記憶體管理,由於保護機制的缺乏,一旦發生Corruption,要有效收斂的難度也相對較高. 但在有MMU的作業系統上,User與Kernel 世界的記憶體可以被切開,而User-Space Cross-Process之間的空間也彼此獨立,若有一個Process有設計上的缺陷,通常都可以控制在該Process運算空間內觸發問題,而針對該流程進行收斂. 若各位也走過non-MMU Real-Time OS到目前功能完備的Linux Kernel這段路,因此也會有所體會的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Linux Kernel文件 “Documentation/memory.txt”,有如下對記憶體的簡述</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>“There are some motherboards that will not cache above a certain quantity of memory. If you have one of these motherboards, your system will be SLOWER, not faster as you add more memory. Consider exchanging your motherboard.”</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者用自己的理解來複述,也就是 <strong>“</strong><strong>不論所使用的處理器多麼的強大,</strong><strong>若不能給予Linux Kernel</strong><strong>足夠的記憶體資源去調度使用,</strong><strong>那系統效率也不會好,</strong><strong>請考慮升級你的硬體” .</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每一個產品開發流程,都會被要求要做記憶體的Cost-Down,因此就有相關記憶體節省或壓榨的技術產生,Linux Kernel 要運作的有效率,包括Buddy System,Per-CPU Page List, Buffer/Cache,到User-Space Mermoy Mapping,File-Mapping..等,若因為記憶體受限,上述機制就會無法被最有效的利用,當然也因此會導致效能上的損耗,有關Memory/Performance 間C/P值的權衡,還是有賴不同產品的設計需求.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>簡單卻又不簡單的機制</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者舉最常見的動態函式庫Mapping最為例子,Linux Kernel為了節省實體記憶體的配置數量,雖然應用程式認知上已經載入該.SO動態函式庫,且該函式庫也已經MMAP到記憶體中,但實際上只有這塊Memory Mapping的範圍被設定好,並沒有真的佔據實體的記憶體空間,等到使用者參考該區域資料產生Data-Abort<strong>(</strong><strong>觸發Kernel</strong><strong>函式do_DataAbort in arch/arm/mm/fault.c)</strong>或是去執行該區域的程式碼產生Prefetch-Abort<strong>(</strong><strong>觸發Kernel</strong><strong>函式do_PrefetchAbort in arch/arm/mm/fault.c )</strong>,Kernel才會真的把資料讀出載入到對應的Memory Page上.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在機制上,雖然應用程式載入一個動態函式庫,但執行期間並不會需要完整的動態函式庫.SO檔案,會依據動態需求,使用不同動態函式庫.SO檔案的各部分內容.因此,透過這樣的機制可省去要把整個.SO與檔案讀取到記憶體的成本,讓應用程式的載入效率提高,節省記憶體成本,以便容納更多應用程式同時運作的需求.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
整體運作概念可參考如下圖所示,應用程式載入動態函式庫後,若執行或參考到尚未被更新到記憶體中的內容,就會觸發Data-Abort/Prefetch-Abort,再透過Kernel機制從外部Storage把對應的資料讀取到記憶體中,並恢復原本觸發這機制的應用程式執行.對應用程式本身,並不會察覺到剛才所使用到的Memory 內容是因為觸發了這段流程才能得以進行,對Kernel而言也藉此機制,可更有彈性去調配記憶體給User-Space的應用程式使用.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwYbPWvufAhlUNO7RnNaPH4eYubyxG0jX9O2WEKERn06zan4LO0FSA1U6mlbDftbAS1weAszW6BlbfmMtRFyv93KnyhzrzzGvPsX_iszE51NlnwRus2TPq9lwJYkRkS-8U9HgdAzWRNCQ/s1600/image001%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="877" data-original-width="1162" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwYbPWvufAhlUNO7RnNaPH4eYubyxG0jX9O2WEKERn06zan4LO0FSA1U6mlbDftbAS1weAszW6BlbfmMtRFyv93KnyhzrzzGvPsX_iszE51NlnwRus2TPq9lwJYkRkS-8U9HgdAzWRNCQ/s1600/image001%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也就是說,一個簡單的應用程式與動態函式庫的執行流程,其實背後卻有如上述流程不簡單的機制輔助著,接下來我們從Memory Node/Zone的概念,來入門Linux Kernel Memory.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Memory Node, Zone</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Linux Kernel Memory Node與Zone彼此關係可參考如下圖所示,在支援NUMA(Non-Uniform Memory Access)的環境下, Kernel Memory可管理一個以上的Memory Node,而每個Memory Node都是一個獨立的Memory節點,具備像是DMA Zone,Low Memory Zone與High Memory Zone,當目前Process所運作的Memory Node所對應的Memory Zone記憶體不足時,可以根據當下Memory Node System Control設定,選擇是要到其它Memory Node的同類型Memory Zone配置記憶體,還是要在自己Local Memory Node上的其它Memory Zone配置記憶體. 當然,如果是後者選擇在同一個Memory Node上配置記憶體,對Local處理器與記憶體存取效率來說會是比較高的.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKo1acujkeDUHqO3w3POP4dx69h5lFV1NI_G1oGfCEKBZgqsTouqDWjaaibjwBHA68PDgPdgdiGpZOlZ4iuTWXlPpnz-9nnX7cVVy4soiPH-M2OUusWfpldb_v862wlkFziQ5wNjX5dwU/s1600/image002%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="872" data-original-width="665" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKo1acujkeDUHqO3w3POP4dx69h5lFV1NI_G1oGfCEKBZgqsTouqDWjaaibjwBHA68PDgPdgdiGpZOlZ4iuTWXlPpnz-9nnX7cVVy4soiPH-M2OUusWfpldb_v862wlkFziQ5wNjX5dwU/s1600/image002%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Linux Memory Node的定義可以參考 nodemask_t node_states 的宣告 (in include/linux/nodemask.h),其中包括了根據當下支援Memory Node最大值MAX_NUMNODES產生的BitMap,與在這BitMap上所對應的Node狀態,包括</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,N_POSSIBLE,</strong>用以表示這個Memory Node是否可以被Online</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,N_ONLINE,</strong>用以表示這個Memory Node是否已經Onlne</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3,N_NORMAL_MEMORY,</strong>用以表示這個Memory Node是否具有Normal Memory Zone</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>4,N_HIGH_MEMORY,</strong>用以表示這個Memory Node是否具有High Memory (若當下Kernel組態不支援High Memory,則此值會等於N_NORMAL_MEMORY)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>5,N_CPU,</strong>用以表示這個Memory Node是否具備CPU (用以決定是否以Local Processor進行 Zone Reclaim)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據所在系統差異, 像是在原本x86環境會提供ISA DMA的DMA Zone (for 24bits, 16MB Memory Range),但在x86-64的64bits環境下,除了原本的DMA Zone外,還會提供DMA32 Zone以供DMA 32bits 4GB記憶體範圍的使用.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">Node 0, zone DMA<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone DMA32</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone Normal</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
相對於x86的I/O Space差異,在ARM處理器上則無DMA Zone.配置</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">Node 0, zone Normal<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone HighMem</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
另一個差異會是,由於32bits處理器所分配的4GB空間通常會是1GB Kernel Space+ 3GB User Space或 2GB Kernel Space + 2GB User Space,若使用者所安裝的記憶體超過1GB,在1GB Kernel Space組態,由於這塊記憶體範圍還包括Kernel Image,vmalloc range,vector,fixmap, iotable mapping, 以致於Kernel會無法Linear Mapping去存取完整的實體記憶體空間,為了讓記憶體的使用有彈性,Linux Kernel 在32bits環境支援了High Memory Zone (目前筆者已知64bits並無需High-Memory),用以去管理在Linux Kernel Linear Mapping Normal Zone上所看不到的記憶體範圍.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
所有Kernel核心物件都還是會從Normal Zone (Low Memory Zone)去進行配置,但像是vmalloc 或 User-Space的記憶體配置,就會盡可能從High Memory Zone配置,以達到記憶體使用最佳化. 接下來,就從Buddy System開始講起.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Buddy System</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Buddy System主要Source Code是在 “mm/page_alloc.c”,有興趣的開發者可以自行參閱. 在總體Physical Memory扣掉Hardware Reserved與Kernel Image本身使用的記憶體空間後,依據Memory Zone的分配,每個Zone範圍內的實體記憶體也就是Kernel Buddy System所管理的範圍.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示, Buddy System會以4kbytes為Page單位細分所管理的記憶體空間,並會根據Memory Zone分配,每個Zone都會有其所對應的Buddy System機制. 而Kernel Image所佔用的記憶體空間會被分配到屬於Normal Zone (也就是 Low Memory)所在區域.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivIdiERW9SQ-um-n0lkY3FQRXEZw47TXQAl9GcH72qpULPd9RWXw90DLCUCCbuwrAqIqAXYPAnV9BR28n8efY8AQaGQzYM7yng95uhp74cMh4zAAhyLKwSNuFoiMVgJ9jBBtM6FXIKsgI/s1600/image003%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="767" data-original-width="1154" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivIdiERW9SQ-um-n0lkY3FQRXEZw47TXQAl9GcH72qpULPd9RWXw90DLCUCCbuwrAqIqAXYPAnV9BR28n8efY8AQaGQzYM7yng95uhp74cMh4zAAhyLKwSNuFoiMVgJ9jBBtM6FXIKsgI/s1600/image003%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">Kernel記憶體管理最殘酷的部份就是在Kernel啟動後一段時間,Physical Memory Fragmentation會讓大塊實體連續的記憶體越來越不容易存在. 如下圖所示,Buddy System會以4kbytes為基礎並以Order 0到Order 10 (也就是有2^0=1 到 2^10=1024個連續Page)為管理的單位進行Free Space的管理工作,並確保在執行過程中,儘可能的讓Page 有被Merge的機會,以便能大塊連續Page有機會產生.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB1KVD6_nkGB-YBqz4K3zCfz-ijRZxdkHcI22nHNVdLpA-HS3DStICUaGEFFcQaCL1EcoZin9wlDzdC7T_KaytLuSg1Go1zrYyVruC6ZZGVTjTT6nE8EjjJCjh9MVxyTAoRBsZw5wOtE8/s1600/image004%255B4%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="868" data-original-width="1171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB1KVD6_nkGB-YBqz4K3zCfz-ijRZxdkHcI22nHNVdLpA-HS3DStICUaGEFFcQaCL1EcoZin9wlDzdC7T_KaytLuSg1Go1zrYyVruC6ZZGVTjTT6nE8EjjJCjh9MVxyTAoRBsZw5wOtE8/s1600/image004%255B4%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對32-bits系統來說,啟動後的Buddy System記憶體分配範例如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">[root@localhost /]# cat /proc/buddyinfo<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone DMA 3 4 5 4 3 3 3 1 2 1 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone Normal 1805 662 318 70 23 17 8 4 3 3 3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone HighMem 68 97 11 14 1 0 0 0 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost /]#</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對64-bits系統來說,啟動後的Buddy System記憶體分配範例如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">[root@ localhost /]# cat /proc/buddyinfo<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone DMA 2 0 1 2 1 1 0 0 1 1 3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone DMA32 2193 2235 1970 1255 463 109 27 2 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone Normal 880 1786 1133 592 255 69 20 8 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@ localhost /]#</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
另外,值得提醒的一點就是,Page Order跟Memory Alignment兩者是有正相關的,也就是說一個Page Order 0的Page起點記憶體位址就一定是跟4096bytes Memory Alignment對齊,如果是一個Page Order 4的Page (=16個4kbytes Pages),也就是連續64kbytes的實體記憶體空間,起點記憶體位址就一定是跟64kbytes Memory Alignment對齊,如果今天有一個Parder Order 4的Page起點記憶體位址並沒有對齊64kbytes Memory Alignment,也就表示這個傳遞進來的Page可能有錯誤發生.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel的文件對Buddy System設計有如下描述, <strong>“Buddy System</strong><strong>的設計為提供direct-mapped table</strong><strong>並以2^Order</strong><strong>進行Memory Block Page</strong><strong>配置,</strong><strong>其中最小為4096bytes Page</strong><strong>的記憶體配置. </strong><strong>每一個Level</strong><strong>都會提供2^Order</strong><strong>的Pages</strong><strong>連續記憶體空間.</strong><strong>每當配置或釋放一個Page</strong><strong>空間時,</strong><strong>都會跟其它的Buddies</strong><strong>有所關係,</strong><strong>例如要配置一個小Block,</strong><strong>就有可能會把一個比較大的Block</strong><strong>分拆成小區塊,</strong><strong>以供這次配置所需,</strong><strong>其它依據大小再拆解成對應2^Order </strong><strong>的Pages</strong><strong>小區塊.</strong><strong>若要釋放一個Block,</strong><strong>並且它旁邊的Buddy</strong><strong>空間也處於Free</strong><strong>的狀態,</strong><strong>此時兩者就可以整合成一個比較大的區塊,</strong><strong>並把這區塊往上升級一個2^Order Page Block”</strong>.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,當要釋放一個Memory Page時,Buddy System會嘗試確認該Page左右兩邊是否為Free,若是就進行Merge,並往上一層Order邁進,以這例子來說,正好釋放一個Order 0的Page,同時左邊Order 0 Page也處於Free狀態,兩者Merge 後,旁邊Order 1的Page也正好處於Free狀態,因此可再進一步Merge成Order 2的Page,若正好Order 2的Page右邊的Page也處於Free狀態,就可以再次往上一個Order Merge,以便創造出足夠大塊的2^Order Free Page.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3Tb_-E7lNXVluUfiD3H7I_e-gIsqlSAlF6lbmR6iTn2iQoX3kS7PYXm9gnbYePX36jRgAldoh2c24EDHKxx2nnBvDVQCU4hb9nJCmesSo20aY7aKlpRBkm9wJdaBI2bwoZcJYglsnWi4/s1600/image005%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="659" data-original-width="1033" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3Tb_-E7lNXVluUfiD3H7I_e-gIsqlSAlF6lbmR6iTn2iQoX3kS7PYXm9gnbYePX36jRgAldoh2c24EDHKxx2nnBvDVQCU4hb9nJCmesSo20aY7aKlpRBkm9wJdaBI2bwoZcJYglsnWi4/s1600/image005%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">再舉另一個Allocate記憶體的例子,如果要配置一個Order 0的Page,但此時恰好系統中只剩下Order 3的Page,系統會把這Order 3的Page進行如下的Split動作,分出一個Order 0 Page供使用者配置使用,並把這Order 3剩下的Page,依序再分配給Order 2,1,0的Free List空間,以供其它Page Allocation需求.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSbWsaavQIDv2A7YkkHkS34Jo036XmVjnz6DlvrdsqAM1C6-1vLriP6oCF454nbKiWsPxfZWbOlzvAOAeGm5-ZIsUxgw_EiFmF2buaexDaSF2nVyPploMMv8dpLr2CLTkNcYbdFDz8WFk/s1600/image006%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="659" data-original-width="1178" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSbWsaavQIDv2A7YkkHkS34Jo036XmVjnz6DlvrdsqAM1C6-1vLriP6oCF454nbKiWsPxfZWbOlzvAOAeGm5-ZIsUxgw_EiFmF2buaexDaSF2nVyPploMMv8dpLr2CLTkNcYbdFDz8WFk/s1600/image006%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
</div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Buddy System的概念,大致簡述如上,後續將針對Buddy System初始化與程式碼,作一個簡要的說明,希望對於Trace Source Code的開發者而言可以有所助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Buddy System </strong><strong>初始化</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Buddy System的初始化,會分為兩個階段,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
第一階段,會執行如下流程,把指定Memory Node的Memory Zone Buddy System初始化,但在這階段每一個對應2^Order的Free Area Link-List都為空,且nr_free為0,還尚未有Free Page可供配置使用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
第二階段,才會把Boot Memory Free出來,並放到對應Buddy System Page Order Link-List中,此時系統才能真的提供Page Allocation的服務.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關第一階段的程式流程如下簡述</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, 從start_kernel 透過setup_arch,進入函式arm_bootmem_free(in arch/arm/mm/init.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 呼叫 free_area_init_node (in mm/page_alloc.c) 以便針對Memory Node 0進行初始化.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, 呼叫 free_area_init_core (in mm/page_alloc.c) 初始化Memory Node上的每一個Memory Zone,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4, 呼叫 init_currently_empty_zone (in mm/page_alloc.c),並帶入Zone Start PFN與Size,以便初始化這個Memory Zone的Buddy System</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5, 呼叫 zone_init_free_lists (in mm/page_alloc.c),透過for_each_migratetype_order初始化Order 0-10 的Zone Free Area與每個Zone Free Area下的Free List Type(包括 MIGRATE_UNMOVABLE,MIGRATE_RECLAIMABLE,MIGRATE_MOVABLE,MIGRATE_ISOLATE..etc)並設定Order 0-10 的 Zone Free Area 初始nr_free為0,至此Buddy System已初始化完畢,但還尚未有Free Page可供Page Allocation使用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
整體概念如下圖所示,屬於Memory Node 0上的Memory Zone Boddy System的 Free Area Order 0-10 所串連的Page Link-List與相關Migration Type都在這階段初始化完畢.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoUQlkgXoFYga9O2upUa8Hwa-3Zn9w9XZ8nkKVGwDESr4lwf2XOWFpALT3Qt_iNMahJteKn-L6uyduULdpP4pYCKvdRKjhByCiGN-_tjQ_LE7qJ3om1-2jdIKVt50GV5pRVwwq-iiDJfY/s1600/image007%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="681" data-original-width="1059" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoUQlkgXoFYga9O2upUa8Hwa-3Zn9w9XZ8nkKVGwDESr4lwf2XOWFpALT3Qt_iNMahJteKn-L6uyduULdpP4pYCKvdRKjhByCiGN-_tjQ_LE7qJ3om1-2jdIKVt50GV5pRVwwq-iiDJfY/s1600/image007%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,在start_kernel 透過setup_arch,呼叫arm_bootmem_free到init_currely_empty_zone-> zone_init_free_lists初始化Zone後, 會回到start_kernel函式繼續往下執行,之後進入函式mem_init,並往後執行free_all_bootmem,會把開機過程中所使用的Boot Memory進行釋放,回到Buddy System中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在走完mem_init之後,Buddy System內對應的Page Order Link-List與nr_free就能反應當下Page Order實際Free Page狀況,並進行Allocate Page.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8DmDrNYeRShWppIgxE5hYeu3zPJ9UEzNUz7Jakdfxug7N3FLNC52BanUvxuhw_pmrhECbjMOiBgki88XKXdWd2s1BOM8uIsUbpVd8kadJrAw9uiG5sst0JAJSjsYjU6_PKLte57pmZy8/s1600/image008%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="877" data-original-width="1171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8DmDrNYeRShWppIgxE5hYeu3zPJ9UEzNUz7Jakdfxug7N3FLNC52BanUvxuhw_pmrhECbjMOiBgki88XKXdWd2s1BOM8uIsUbpVd8kadJrAw9uiG5sst0JAJSjsYjU6_PKLte57pmZy8/s1600/image008%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
提到Buddy System概念與初始化後,再來會舉實際配置與釋放的例子,作簡要說明</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Buddy System Memory Allocation and Free</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下,筆者以基於Slub的Kernel Memory 配置流程加以說明,其中有關kmem_cache_alloc_trace,trace_kmalloc的Trace機制,在本文中將不涉及.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者以函式__get_free_pages (in mm/page_alloc.c)為例,這是一個在Kernel Space用以配置Normal Memory的機制,並回傳已Mapping到虛擬記憶體空間的Address. 函式__get_free_pages在Kernel中使用廣泛,像是 ARM Page Table 的第一層 16kbytes,就會透過 pgd_alloc->__pgd_alloc 執行 __get_free_pages(GFP_KERNEL, 2),透過 Buddy System 挖取一個Page Order 2,也就是4*4kbytes = 16kbytes的第一層Page Table.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所述為__get_free_pages (in mm/page_alloc.c)的運作流程</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,若判斷 gfp_mask & __GFP_HIGHMEM 為真,則觸發 VM_BUG_ON</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(__get_free_pages </strong><strong>只用來配置</strong><strong> Linear Mapping</strong><strong>的記憶體區塊</strong><strong>,</strong><strong>並透過</strong><strong>page_address</strong><strong>返回取得</strong><strong>Page</strong><strong>對應的</strong><strong>Kernel Memory Virtual Address)</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫alloc_pages執行函式alloc_pages_node (in include/linux/gfp.h),透過Buddy System挖取對應Order大小的Pages</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-1,若 Memory Node ID<0,則呼叫 numa_node_id取得目前的Memory Node ID</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2,呼叫__alloc_pages (in include/linux/gfp.h)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1,呼叫__alloc_pages_nodemask (in mm/page_alloc.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-1,確認透過node_zonelist(Memory_Node_ID, gfp_mask)所取得的Zone List->_zonerefs->zone是否包括有效的Memory Zone符合在對應Memory Node上的Memory GFP Mask,若在所使用的Memory Node上無法找到符合Memory GFP Mask有效的Memory Zone則會返回NULL表示Allocate Page操作失敗.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-2, 呼叫first_zones_zonelist, 取得第一個Zone,或在許可的Memory Node上 zonelist中 highest_zoneidx的下一個Zone.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-2-1, 呼叫next_zones_zonelist,取得下一個Zone,或在zonelist中 highest_zoneidx的下一個Zone.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-3, 若無法透過first_zones_zonelist取得有效的Memory Zone <strong>(</strong><strong>可能在同一個Memory Node</strong><strong>或不同的Memory Node</strong><strong>上的有效Memory Zone)</strong>,則執行goto out,若此時其它Race Condition下的Thread也更新狀態,讓原本Failed準備要goto out的Page Allocation機制有機會成功,就會執行goto retry_cpuset,嘗試讓Page Allocation成功.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-4, 呼叫get_page_from_freelist並帶入上一步選中的preferred_zone,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-4-1,透過for_each_zone_zonelist_nodemask,基於cpuset_zone_allowed選擇一個有足夠Free Pages的Memory Zone</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-4-2,若Memory Zone內的File Dirty PageCache,NFS Unstable Pages,或Writeback Pages總數超過zone_dirty_limit,表示該Memory Zone已經滿了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-4-3,若alloc_flags & ALLOC_NO_WATERMARKS不成立,則進入 2-2-1-4-3-1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-4-3-1,若Zone內的Free空間滿足Watermark水位的要求,則直接進入try_this_zone,呼叫函式buffered_rmqueue從對應的Memory Zone上取得Page.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-4-3-2,反之就會進入zone_reclaim流程,直到確定Zone內的Free空間滿足Watermark水位的要求</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-4-4,若alloc_flags & ALLOC_NO_WATERMARKS成立, 則直接進入try_this_zone,呼叫函式buffered_rmqueue從對應的Memory Zone上取得Page.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-4-4-1,呼叫buffered_rmqueue,在函式buffered_rmqueue中,如果要配置的記憶體是Order=0,會先嘗試從Per-CPU Page List快取中取得Page,並會關閉中斷,避免像是Drain All Pages的流程觸發IPI中斷回收Per-CPU Page List快取,導致兩者行為交互上的錯誤.若此時,Per-CPU Page List為空,則透過rmqueue_bulk往Buddy System挖Page,反之就從 Per-CPU Page List快取取得Page.若Order>0,就直接從Buddy System挖.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1-5, 呼叫__alloc_pages_slowpath, 由於嘗試直接配置記憶體失敗,進入到__alloc_pages_slowpath慢速的路徑後,會嘗試喚醒kswapd Kernel Thread進行記憶體回收,在進行相關Reclaim流程時,會再嘗試透過get_page_from_freelist進行配置,若允許ALLOC_NO_WATERMARKS的配置方式,則在此會透過__alloc_pages_high_priority再嘗試一次.如果Process Flag中TIF_MEMDIE成立,表示該Process正在被結束中,若是則直接結束Slow Path記憶體配置.若上述流程都還是配置不到記憶體,則會根據條件依序進行 __alloc_pages_direct_compact,__alloc_pages_direct_reclaim 與最後一關搭配OOM(Out-Of-Memory) Killer 的__alloc_pages_may_oom,強制系統透過砍Process釋出足夠的記憶體空間.最後會根據條件,判斷是否要再 goto rebalance,重複上述流程. (繼續努力讓系統可以擠出記憶體)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,呼叫page_address,執行lowmem_page_address 傳回 Linear Mapping Address.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在以函式__get_free_pages簡述Page Allocation的例子後,筆者以 __free_one_page(in mm/page_alloc.c)說明Page釋放回到Buddy System的流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,透過PageCompound判斷是否為連續Page的一部分,若是,則呼叫destroy_compound_page,確認是否能夠被Free (若返回bad值>0就直接結束Free Page流程)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,取得Page Frame Number,確認該Page是否在Buddy System同一Order中的第一個Page,如果不是就會觸發VM_BUG_ON,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">舉例來說,要觸發一個Order=4的Page,而傳入Page的PFN=4096,系統支援的最大MAX_ORDER=11,因此<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
page_idx = page_to_pfn(page) & ((1 << MAX_ORDER) – 1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
= 4096 & ((1 << 11)-1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
= 4096 & 0x7FF</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
= 0x00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再把page_idx跟當下傳入Page Order作如下計算</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(page_idx & ((1 << order) – 1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果結果為0,表示傳入的Page Frame Number是在 Order 4 = 16 的倍數,以就是合法的PFN. 如果不為0,就表示傳入的PFN是在Order 4 這16個Page連續記憶體的中間 (也就是說不是Order 4的第一個Page.) .那就表示這個Page是無效Page,就會觸發 VM_BUG_ON</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,呼叫bad_range,確認Page是在Memory Zone內的有效範圍</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,進行釋放Page流程,並確認當前釋放的Page,是否可以跟前後的Buddy Page整合為一個更大的Page (需符合 Buddy System對Order的要求),若能就整合,反之就結束合併Buddy Page的流程</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,呼叫 set_page_order 設定Page Order ((page)->private=Order and __SetPageBuddy)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,透過page_is_buddy查核目前Page的Buddy Page的下個Page是否為Free,Buddy 並有更高一階有的 Order, 若是就透過list_add_tail把目前的Page放在zone->free_area[order].free_list[migratetype]的後面,以便當中間使用中的Page被釋放時,兩個Free Buddy可以合併成一個更大的Buddy,再跟原本就已經Free的高一階Buddy整合, 成一個更大的Buddy.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,若6不成立,就透過list_add把這個Page放到 zone->free_area[order].free_list[migratetype]的前面,根據目前free_list的操作,放在越前面的Page會被越快用到. (除非有第6點企圖要整合成一個更更高一階Order的目的,不然就還是會固定放在Link-List的頭端)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
上述有關Free Page確認下一個Buddy Page是否為Free,並把目前要 Free的Page放到對應Link-List尾端,等待中間還在被使用的Order =1 (=2 Pages)被釋放後,就機會更快讓系統得到連續的Order=3 Page概念,筆者圖示如下</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxipFl1LstsrnEIOgHkESGqqdSv4YCL5oUQnx0G1zgHs9saEYPZZxGiYTkyNV6E3GFbYUKBLWEvaVmqFKvtmuVXM-VQkz-DYeDbwrARMSNeg51v1DWlgT1wS8AfowQZJLt3yQcrK1zBM4/s1600/image009%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="596" data-original-width="1155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxipFl1LstsrnEIOgHkESGqqdSv4YCL5oUQnx0G1zgHs9saEYPZZxGiYTkyNV6E3GFbYUKBLWEvaVmqFKvtmuVXM-VQkz-DYeDbwrARMSNeg51v1DWlgT1wS8AfowQZJLt3yQcrK1zBM4/s1600/image009%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來讓我們介紹Per-CPU PageList,這是一個用以加速Buddy System運作的快取機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Per-CPU PageList</strong><strong>機制</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
User/Kernel Space應用程式的運作中,Order 0 Page是所有需求中數量最多,Allocation/Free最頻繁的Order,主要原因在於包括User-Space Malloc/Free 或Kernel Space的vmalloc,都會是以 Order 0 Page透過虛擬記憶體的操作提供連續的虛擬記憶體空間. 也因為如此,如果每次都要頻繁的去Buddy System進行Order 0 Page的Merge/Split,無形中也成為一個Bottleneck,若能有效的降低Order 0 Page大量操作下的成本,對系統效能將有顯著的改善.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Kernel目前支援Per-CPU PageList的機制,用以在直接去Buddy System找 Order 0 Page前,可以有一個快取機制,能直接供應Order 0 Page操作,作為改善的機制. Per-CPU PageList對應的結構為 “struct per_cpu_pages *” ,如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">struct per_cpu_pages {<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int count; <strong>=> </strong><strong>表示目前在Per-CPU PageList</strong><strong>中的Order 0 Page</strong><strong>個數.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int high; <strong>=></strong><strong>作為Per-CPU PageList</strong><strong>的high watermark,</strong><strong>當在List</strong><strong>中儲存的Page</strong><strong>個數超過這值時,</strong><strong>就會呼叫函式free_pcppages_bulk,</strong><strong>並參考batch</strong><strong>數值,</strong><strong>將Order 0 Page</strong><strong>還回給系統.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int batch;<strong> =></strong><strong>可用以指定每次還Order 0 Page</strong><strong>給系統時,</strong><strong>透過free_pcppages_bulk</strong><strong>所要釋放的Page</strong><strong>個數. </strong><strong>或當發現Per-CPU PageList</strong><strong>中為空時,</strong><strong>也會透過rmqueue_bulk</strong><strong>搭配這個batch</strong><strong>數值,</strong><strong>用以配置基本數量的Order 0 Page</strong><strong>給Per-CPU PageList,</strong><strong>以達到快取的目的. </strong><strong>由此可知batch</strong><strong>值的定義,</strong><strong>對於Buddy System </strong><strong>快取的改善是有很重要的角色.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct list_head lists[MIGRATE_PCPTYPES]; <strong>=></strong><strong>用以儲存Per-CPU PageList</strong><strong>對應不同Page Migration Type</strong><strong>的Link List Array.</strong><strong>目前支援三種 Type,Migration Movable/Unmovable</strong><strong>與Reclaimable</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在多核心的環境下,drain_all_pages (in mm/page_alloc.c)是很常被呼叫到的Kernel Memory Management機制,例如在__alloc_pages_direct_reclaim或alloc_contig_range,這些配置記憶體的操作上,若有遇到記憶體不足時,就會透過drain_all_pages,呼叫on_each_cpu_mask,透過SMP IPI觸發中斷讓每個處理器執行drain_local_pages,並呼叫函式drain_pages(in mm/page_alloc.c),透過free_pcppages_bulk 釋放目前在 Per-CPU PageList 快取的Pages,讓這些Pages可以回到 Buddy System中, 重新被配置使用,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
free_hot_cold_page (in mm/page_alloc.c)主要用以釋放Order 0 的Page,並加入到 Per-CPU PageList中,Per-CPU PageList所管理的pcp->lists (in include/linux/mmzone.h),MIGRATE_PCPTYPES 用以表示目前Per-CPU PageList所支援的Page Type總數. (以Linux Kernel 3.5.4而言此值為3),Per-CPU PageList 主要支援以下的Migration Type,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>MIGRATE_UNMOVABLE:</strong>Page屬性為 Unmovable</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>MIGRATE_RECLAIMABLE:</strong>Page屬性為 Reclaimable</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>MIGRATE_MOVABLE:</strong>Page屬性為 Movable</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此外,若 Page屬性為Isolation (=MIGRATE_ISOLATE),就會透過free_one_page直接釋放掉,而不會進到Per-CPU PageList快取中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,如果是Cold Page,會呼叫list_add_tail放到Per-CPU PageList “pcp->lists[migratetype]” 的最後面</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,如果是Hot Page,會呼叫list_add 放到Per-CPU PageList “pcp->lists[migratetype]” 的最前面</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,最後並把 Per-CPU PageList Count 加一 “pcp->count++”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,如果pcp->count大於 Per-CPU PageList的高水位 “pcp->high” (也就是Per CPU PageList中的Page個數太多了), 就會透過free_pcppages_bulk釋放pcp->batch筆數,並修正pcp->count的統計.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在介紹完基本Buddy System的概念與流程後,另一個筆者覺得也很值得介紹的議題就是Kernel Image的Memory Layout,對Kernel Image在記憶體中的Layout與範圍清楚,對於核心問題的解決上,總是可以多了更多的背景輔助知識,用以處理產品化的問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Kernel Image</strong><strong>的</strong><strong>Memory Layout</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
既然要介紹Kernel Image Layout,筆者希望能以各位也可以取得的環境來做驗證,選擇的Source Code為HTC OneX Linux Kernel 3.0.8 (可自<a href="http://htcdev.com/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://htcdev.com</a> 下載),並以 arm-eabi-gcc (GCC 4.4.3) 進行編譯.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這版Kernel Source Code的CONFIG_PAGE_OFFSET設定為0xC0000000,因此Linux Kernel會從0xc0008000開始載入到記憶體 (前面的0xc0004000-0xc0007fff 為啟動過程配置為1MB Section的Page Table).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
編譯後的Kernel Image, Section to Segment mapping 會如下所示,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">Segment Sections…<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00 .init .data..percpu</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
01 .text</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
02 .rodata __bug_table __ksymtab __ksymtab_gpl __kcrctab __kcrctab_gpl __ksymtab_strings __init_rodata __param __modver .ARM.unwind_idx .ARM.unwind_tab</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
03 .data .notes .bss</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可參考這版Kernel Source Code Linker Script的配置 (in arch/arm/kernel/vmlinux.lds ),在上述Segments之間會加入 <strong>“. = ALIGN(1<<20);”</strong>標示,讓這些Segments在編譯為Kernel Image後,彼此的記憶體間隔會<strong>是</strong><strong>1MB Memory Alignmen</strong>t.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,是筆者以上述OneX Kernel Image載入到記憶體後的Layout,最前面兩個Section分別為 .init (屬於BSS Data Section),與 .data..percpu (屬於Data Section,用以記錄在 Multi-Processor下的Per CPU Data變數).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來就是程式碼區塊,由於Kernel 支援像是Tracer或Jump Label這類會修改Linux Kernel Code Segment的機制,也因此不像是一般ELF應用程式會把Code Segment設定為Read-Only,在Linux Kernel中的Code Segment本身會是可以寫入的. 好處當然是有關的Tracer或改善效能的機制可以更有彈性被加入,但缺點就是如果有一個核心模組存在程式碼撰寫上的缺陷,就有機會導致Kernel Code Segment的Corruption,導致不預期的錯誤發生. 在.text section之後為 .rodata (屬於RO Data Section),與 Kernel Symbol/Unwind等有關的Section (屬於RO Data Section). 再來就是可讀可寫的 .data section (屬於Data Section)與 .bss section (屬於BSS Data Section).</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5rFHSzdveFacB8Y6wBk2f-W7r5Gm3kIG4IL0pbpQ4vhKOdPRppRY3-JRSrLXg8-vr_52VoDAd7MzemgQougmz0_UOv6su0Xn3n7B6lv8ZFu4yAB97nXEvgtsI6feDffK15w-jfPWKNrc/s1600/image010%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="623" data-original-width="1046" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5rFHSzdveFacB8Y6wBk2f-W7r5Gm3kIG4IL0pbpQ4vhKOdPRppRY3-JRSrLXg8-vr_52VoDAd7MzemgQougmz0_UOv6su0Xn3n7B6lv8ZFu4yAB97nXEvgtsI6feDffK15w-jfPWKNrc/s1600/image010%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但由於.init section 與 .data..percpu section兩者總和並佔不滿1MB的記憶體範圍,在接續到.text section中間會有空間浪費的問題,若不希望造成記憶體的閒置,可以把 Alignment縮小,以筆者的驗證來說,可以改為4kbytes Alignment,例如 <strong>“. = ALIGN(1<<12);”</strong>,編譯後的Section to Segment mapping 會如下所示,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">Segment Sections…<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00 .init .data..percpu .text .rodata __bug_table __ksymtab __ksymtab_gpl __kcrctab __kcrctab_gpl __ksymtab_strings __init_rodata __param __modver .ARM.unwind_idx .ARM.unwind_tab .data .notes .bss</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從.init section 到 .bss section結尾所佔用記憶體的空間,會從原本的0xc0008000 到 0xc0edcddc,變成改為 4kbytes alignment後的0xc0008000 到 0xc0cd4ddc, 若以 .bss section 結尾位置來比較的話,大概相差了 2MB.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_aej-JqModNi7NDDtYkOI1Ku0TFScF0l9tL5TL7bp61hNRyHsfAME9GUWjhxvRGBIMmzL2uMdd9AkeDIszDMQ8J-HPDSJZtYWzbVoxl9130D3fWAt2ZarRSl9z07ENVcG98F_ptEH_dU/s1600/image011%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="516" data-original-width="1051" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_aej-JqModNi7NDDtYkOI1Ku0TFScF0l9tL5TL7bp61hNRyHsfAME9GUWjhxvRGBIMmzL2uMdd9AkeDIszDMQ8J-HPDSJZtYWzbVoxl9130D3fWAt2ZarRSl9z07ENVcG98F_ptEH_dU/s1600/image011%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在開發階段,如果希望便於除錯或是硬體有支援Memory Protection除錯能力,把Segment範圍對齊硬體Memory Protection的Alignment位址,反而有利於偵測硬體或處理器Memory Corruption的錯誤發生,只要最後產品化階段,把記憶體的Alignment調整回來即可,至於如何權衡還需以當下需求為主.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從Kernel.org 所下載的Linux Kernel, ARM環境原本配置就是 4kbytes Page Alignment, 若無特別除錯需求的考量,是不需要額外修改的.本節是以HTC OneX 使用的Linux Kernel 3.0.8為例.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
既然談了Memory Node,Zone,Buddy System與Kernel Image Memory Layout,另一個筆者覺得基礎的主題就是VMalloc 與 High Memory Zone的配置,將在下個段落中加以說明.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>VMalloc </strong><strong>大小與</strong><strong>VMalloc Guard Zone</strong><strong>的關係</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
假設,使用者的 Kernel command line 設定 vmalloc=546M,此時</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vmalloc : 0xdd000000 – 0xff000000 ( 544 MB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lowmem : 0xc0000000 – 0xdce00000 ( 462 MB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以知道vmalloc 起點 0xdd000000距離lowmem終點 0xdce00000 有2MB的Guard Zone.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若是設定 vmalloc=549M,此時</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vmalloc : 0xdd000000 – 0xff000000 ( 544 MB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lowmem : 0xc0000000 – 0xdcb00000 ( 459 MB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Guard Zone長度變為5MB,VMalloc位址起點還是不變為0xdd000000,但lowmem結尾卻往後退到0xdcb00000.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再更進一步, 設定vmalloc=552M,此時</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vmalloc : 0xdd000000 – 0xff000000 ( 544 MB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lowmem : 0xc0000000 – 0xdc800000 ( 456 MB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Guard Zone長度變為8MB,VMalloc位址起點還是不變為0xdd000000,但lowmem結尾卻往後退到0xdc800000.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後,我們設定vmalloc=553M,此時</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vmalloc : 0xdc800000 – 0xff000000 ( 552 MB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lowmem : 0xc0000000 – 0xdc700000 ( 455 MB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Guard Zone長度變為1MB,VMalloc空間由544MB變成552MB,位址起點變為0xdc800000,而lowmem結尾往後退到0xdc700000.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
綜合上述的驗證流程,我們可以看到當設定一個VMalloc大小時,系統會以該VMalloc往下找第一個8MB Alignment的位址最為VMalloc虛擬記憶體空間的起點 (以就是說一定確保VMalloc空間Start起點是8MB Alignment的記憶體位址).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也因此,根據啟動時傳給Kernel Command Line VMalloc值的大小,位於VMalloc與Low Memory中間的Guard Zone可以有1MB-8MB的變化,這只會影響到虛擬空間的改變,當 Guard Zone變大導致Low Memory空間變小,就會讓HighZone空間對等變大,也就是說使用者總體可使用的實體記憶體變沒有減少,只是轉由直接Linear Mapping的Low Memory,變成透過High Zone取得.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>談系統</strong><strong>High Memory Zone</strong><strong>的配置</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
提到Linux Kernel記憶體管理, Memory Zone觀念是最為基礎的項目,在32bits系統User-Space與Kernel Space必須要能共用這塊4GB的虛擬記憶體空間.通常Kernel-Space跟User-Space的比例可以為1GB vs 3GB或2GB vs 2GB,而一般Android環境下的Linux Kernel若無意外設定通常會是1GB vs 3GB,如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNuki7rClLK-F9ebyyMzlVvAXyiDHViBd47tHN2hmsIUka3cETYy1XexwioIGraZyvvTMOXdsVGTOzWcbjZjEiFvDrCLGWe4weHkbq1s0WI2QWu49Jw9dR6sDonBETROPUfTWCWMrh6-E/s1600/image012%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="816" data-original-width="823" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNuki7rClLK-F9ebyyMzlVvAXyiDHViBd47tHN2hmsIUka3cETYy1XexwioIGraZyvvTMOXdsVGTOzWcbjZjEiFvDrCLGWe4weHkbq1s0WI2QWu49Jw9dR6sDonBETROPUfTWCWMrh6-E/s1600/image012%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如前述包括Kernel Image,vmalloc range,vector,fixmap, iotable mapping,都會導致這1GB Kernel Space記憶體空間的使用加速,結果就是並非所有實體記憶體都有機會被對應到這1GB的記憶體空間來,無法對應到這1GB實體空間的記憶體,就會透過另一個Memory Zone進行配置,也是稱的High-Memory Zone.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,Normal Zone會Linear Mapping到Low Memory區域,也,就是說屬於Normal Zone區塊的記憶體範圍,都是Kernel在Run-Time運作時可以直接參考到的,而位於High-Memory Zone的記憶體則一定要透過vmalloc mapping到Kernel Space虛擬記憶體空間,才可透過Kernel進行定址與操作.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtPHomBPR2K9hp6I4joqWXLTwL32hwluIjYOY_HZMPKtNdZmAEmvefZmCqPwdXKS2frA-pSHyjDJRHS1ZmFSrtXyvXkxoY1XY52cUA5KvKWs0ONcfS8IqxO1CTDJKfZvRgiQh3F7fd-Nw/s1600/image013%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="605" data-original-width="1178" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtPHomBPR2K9hp6I4joqWXLTwL32hwluIjYOY_HZMPKtNdZmAEmvefZmCqPwdXKS2frA-pSHyjDJRHS1ZmFSrtXyvXkxoY1XY52cUA5KvKWs0ONcfS8IqxO1CTDJKfZvRgiQh3F7fd-Nw/s1600/image013%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般Linux Kernel根據Kernel Space虛擬記憶體範圍與VMalloc配置的大小,決定系統是否需要存在High-Memory Zone,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但在Kernel 3.4後, VMalloc空間計算有了改變,必須要加入I/O Table Mapping Memory Size合併計算,有關VMalloc空間與I/O Table Mapping合併的歷史,可以參考 3.4.0 的這版Patch, “ARM: move iotable mappings within the vmalloc region” (<a href="http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=commitdiff;h=0536bdf33faff4d940ac094c77998cfac368cfff" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=commitdiff;h=0536bdf33faff4d940ac094c77998cfac368cfff</a>),作者Nicolas Pitre撰寫的描述如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="684"><strong>In order to remove the build time variation between different SOCs with regards to VMALLOC_END, the iotable mappings are now allocated inside the vmalloc region. This allows for VMALLOC_END to be identical across all machines.</strong><strong><br />The value for VMALLOC_END is now set to 0xff000000 which is right where the consistent DMA area starts.<br />To accommodate all static mappings on machines with possible highmem usage,the default vmalloc area size is changed to 240 MB so that VMALLOC_START is no higher than 0xf0000000 by default.</strong><strong></strong></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以ARM Linux來說通常,0xff000000 以上16MB空間為 fixmap與vector, 再來就是 VMalloc, Guard Zone與LowMem.要預估一個系統中是否存在High-Memmory Zone以及該High-Memory Zone的大小,最好的方式就是估出Low Memory Zone大小(含Kernel Image 佔用的Code/Data Size),在跟實際記憶體計算即可.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉例來說,Linux 裝置上有1024MB的記憶體,扣除Hardware Reserved 64MB後,還剩下960MB實體記憶體. 同時,在這裝置的虛擬記憶體空間1GB Kernel Spae包括VMalloc 配置為300MB與224MB I/O Table Mapping (其中包括4MB Guard Zone),因此Low Memory Zone的空間會有 1024 – 16 (0xff000000以上空間) – 296-4-224=484MB.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來把實體記憶體1024MB大小減去Hardware Reserved 64MB與減去Low Memory Zone 484MB,就可以得到High-Memory Zone的大小應為1024-64-484=476MB.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
所以最後的系統會存在</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0,總共1024MB實體記憶體</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, 64MB Hardware Reserved Memory</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 296MB VMAlloc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, 4MB VMAlloc Guard Zone</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4, 224MB I/O Table Mapping</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,484MB Low-Memory Zone (Normal Zone)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,476MB High-Memory Zone</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在談了相關Kernel Memory設計邏輯後,最後補充說明/proc下的Memory Information與Control機制,供開發者參考.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Proc FileSystem Memory Information</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel Memory Management除了前述有關的設計邏輯外,對剛入門的開發者而言,最需要解決的是眾多的名詞與邏輯,其他包括在 /proc目錄下提供的Kernel Memory資訊,或是再 /proc/sys/vm目錄下提供的Kernel Memory控制機制. 筆者在此針對自己認為比較重要與需要理解的部份作一個說明,由於名詞與含義眾多,若非原本就已經很熟悉的開發者,就只要大概知道這些名詞就好,等到真的有需求時,再來翻閱本文或其它各位覺得便利的技術資料即可.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/Buddyinfo</strong><strong>è</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Kernel的Buddy System會以Page Order為單位去Group所管理與使用的外部實體記憶體,Kernel會以Order 0,1,2,3,4,5,6,7,8,9,10,也就是從 Order 0 一個Page 4096kbytes大小,到Order 10提供約4MB大小的Memory配置,根據每種不同大小的連續記憶體的使用狀況,可把被釋放的記憶體組合為更上一階的Memory Page Oder,或是把連續的記憶體根據需求拆解為所需的Page Order不同大小的記憶體區塊,而這些當下Buddy System對記憶體管理的使用情況,就是BuddyInfo所可以提供的即時記憶體使用資訊,當所要配置的記憶體Page Order正好落在目前Buddy System所無法供應的連續記憶體區塊時,就可能會導致記憶體配置失敗. (會透過 Low Memory Killer 或 OOM (當一個Page配置都失敗時)來強制透過應用程式的刪除執行,配置出足夠大小的連續實體記憶體空間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下表所示,解決Kernel 使用外部Physical Memory的Fragmentation一直都是在記憶體管理上非常重要的課題.而BuddyInfo就是可以提供開發者了解目前Linux Kernel Memory Page使用狀況的Proc Filesystem Node,透過BuddyInfo的資訊,我們可以知道當下Kernel Memory Fragmentation的程度,以及知道哪一檔次Order的Memory,在現在記憶體配置時,是會導致失敗的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 890px;"><tbody>
<tr><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="63"><strong>Node</strong></td><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="98"><strong>Zone</strong></td><td colspan="11" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="730"><strong>Order</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>1</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>2</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>3</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>4</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>5</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>6</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>8</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>9</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>10</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="63"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="98"><strong>DMA</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>8</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>10</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>8</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>8</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>6</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="63"><strong>0</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="98"><strong>Normal</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>488</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>144</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>73</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>14</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>v</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>2</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="63"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="98"><strong>HighMem</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>16</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>2</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>1</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>1</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>1</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="66"><strong>0</strong></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每一列都表示當下指定Node與Zone中對應Page Order的數量,例如在表中有8個2^1*PAGE_SIZE大小的Zone DMA,或14個2^3*PAGE_SIZE大小的Zone Normal空間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而另一個關係到Fragmentation可供參考的Proc Node 為 pagetypeinfo,詳細說明可參考如下段所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/pagetypeinfo </strong><strong>è</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除了可以看到Buddy System對應不同Page Order的數量外,還可以根據以Migration Type分類的方式,並以連續記憶體範圍來分類Page Blocks,例如假設在這個Zone中有10個Page,其中連續區塊為 3,3 4個Pages區塊,在Pagetypeinfo中,” Free pages count per migrate type at order” 會根據Migration Type以Page個數為單位來作計算總共有10個Pages,但在 “Number of blocks type”統計中,則會依據總共是三個連續區塊的組合,而計算該Migration Type總共有3個Blocks.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於Migration Type,有關 “Movable” 與 ” Reclaimable” blocks也會是屬於Allocatable, 除非Memory Page被設定為mlock,也就是說會脫離LRU Active/Inactive Anonymous/File-Mapping Memory Pages以外的範圍.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 851px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="851"><strong>Page block order: 10</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Pages per block: 1024</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone DMA, type Unmovable 0 0 0 1 1 1 1 1 1 1 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone DMA, type Reclaimable 0 0 0 0 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone DMA, type Movable 1 1 2 1 2 1 1 0 1 0 2</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone DMA, type Reserve 0 0 0 0 0 0 0 0 0 1 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone DMA, type Isolate 0 0 0 0 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone Normal, type Unmovable 502 1 0 0 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone Normal, type Reclaimable 14 0 0 1 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone Normal, type Movable 1 18 8 2 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone Normal, type Reserve 67 26 9 14 7 1 2 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone HighMem, type Unmovable 0 0 0 0 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone HighMem, type Reclaimable 0 0 0 0 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone HighMem, type Movable 7 0 0 0 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone HighMem, type Reserve 0 0 1 1 1 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone HighMem, type Isolate 0 0 0 0 0 0 0 0 0 0 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Number of blocks type Unmovable Reclaimable Movable Reserve Isolate</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone DMA 2 0 5 1 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone Normal 23 2 85 1 0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Node 0, zone HighMem 3 0 7 1 0</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/meminfo </strong><strong>è</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
主要用以提供Memory Distribution/Utilization的使用狀況,有關meminfo顯示的程式碼部分,可參考線上的Source Code Reference (<a href="http://hala01.com/src/linux/linux-3.5.4/HTML/S/6483.html#L22" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.5.4/HTML/S/6483.html#L22</a>),</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">名稱</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">MemTotal: 482104 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">顯示目前Linux Kernel 所可以管理的所有記憶體總數,計算方式為總體實體記憶體,扣除硬體Reserved的部份,與Kernel Image本身所佔用的記憶體,就是屬於Linux Kernel Memory Management所可以管理的實體記憶體總數. 也就是在這所顯示的數值.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">MemFree: 4460 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">會顯示目前位在 HighMemory與LowMemory中Free的Memory總數.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Buffers: 9208 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">屬於Buffers的記憶體會直接對應到Block Device區塊.用以作為Raw Disk Block的記憶體暫時儲存區域,會隨著記憶體與磁碟而增長. (例如在筆者的Server上這個值就超過1GB.).</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Cached: 101256 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">作為檔案系統檔案讀取時的記憶體快取(Page Cache),用以加上基於VFS檔案系統讀取時的效率.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">SwapCached: 112 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">由於Swap-Out (把Page從高效率的Memory寫到外部Storage裝置中) 與 Swap-In(Back) (把Page從外部Storage讀取回到高效率的Memory上),只要涉及到外部儲存裝置的存取動作,都會導致系統效能的降低<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因此SwapCached這塊記憶體的功能主要用於讓程式會使用到的Memory內容在Swap-Out/In過程中,可以暫存在此作為SWAP Device的快取記憶體,避免頻繁的存取外部Storage,節省在I/O等待的時間.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Active: 305388 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">一般User-Space配置記憶體會透過Anonymous或File-Mapping的方式,例如malloc會透過mmap配置屬於MAP_ANONYMOUS的記憶體,或進行從Storage上把檔案Memory Mapping到使用者記憶體空間的操作.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
兩者差別在於Anonymous是作為一般程式碼運作過程中所配置使用的記憶體內容,而File-Mapping這塊記憶體比較像是讓一個實體存在的檔案被貼到記憶體中存取或是執行 (.so),而對於User-Space而言,除了特別的Device Node會經由Kernel Module透過vmalloc/kmalloc配置記憶體外,由Linux Kernel開放給User-Space使用的記憶體就只有透過Anonymous或File-Mapping這兩個途徑.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在這所指的Active,就是屬於Anonymous或File-Mapping透過LRU(Least Recently Used)屬於Active (也就是被定義為活躍還有持續在存取的記憶體內容.).</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Inactive: 56336 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">如前述, Inactive為透過LRU(Least Recently Used)機制定義為非Active的Page,並可在後續記憶體配置有需要時,觸發Page-Reclaim回收給當下需要記憶體的程式使用.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(</strong><strong>只有放在LRU</strong><strong>中的記憶體才會面臨是否要被Page-Reclaim</strong><strong>的行為,</strong><strong>或是屬於Unevictable</strong><strong>或是藉由vmalloc/kmalloc</strong><strong>所配置出來的記憶體,</strong><strong>就不會被Page-Reclaim</strong><strong>機制所回收)</strong><strong></strong></div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Active(anon): 252496 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">屬於LRU(Least Recently Used) Anonymous Active(=LRU_ACTIVE_ANON) 的記憶體總量.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Inactive(anon): 272 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">屬於LRU(Least Recently Used) Anonymous Inactive(=LRU_INACTIVE_ANON) 的記憶體總量.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Active(file): 52892 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">屬於LRU(Least Recently Used) File-Mapping Active(=LRU_ACTIVE_FILE) 的記憶體總量.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Inactive(file): 56064 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">屬於LRU(Least Recently Used) File-Mapping Inactive(=LRU_INACTIVE_FILE) 的記憶體總量.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Unevictable: 5628 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">屬於LRU(Least Recently Used) Unevictable(=LRU_UNEVICTABLE) 的記憶體總量.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Mlocked: 16228 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以統計有被執行mlock的Page數目. (若Page存在LRU中,就會被改放到Unevictable List中).</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">HighTotal: 45056 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示目前屬於High Memory的記憶體總量,通常Kernel Space虛擬記憶體的起點會是0xc0000000-0xfffffff 這段約1GB的範圍,當實體記憶體空間超過Kernel所能定址的虛擬記憶體範圍時,這時Kernel 會需要提供一個機制,把能直接定址的記憶體範圍區分為Low Memory,而無法直接定址的記憶體範圍定義為High Memory,當要取得vmalloc 或 User-Space這類無需實體Linear Mapping的記憶體時,就會優先透過High-Memory Zone來取得,並透過這樣的機制,讓Kernel 也可以去善用這塊非實體Linear Mapping的記憶體空間.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
HighTotal的大小,則需視所在Kernel虛擬記憶體空間(from 0x80000000 or 0xc0000000)與當下的實體記憶體配置大小而定.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">HighFree: 140 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">承上,除了vmalloc與User-Space記憶體外,像是檔案系統PageCache也會透過High-Memory進行配置. 而HighFree則用以表示當下屬於High-Memory區塊還有多少尚未被使用的空間.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">LowTotal: 437048 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">相對於High-Memory, Low Memory就是指可以被Kernel Linear Mapping的實體連續記憶體空間,像是kmalloc/kmem_cache這類需要實體連續記憶體配置的操作,就會透過Low Memory取得. 而當High-Memory Zone能提供的記憶體不足時,也會選擇透過Low Memory進行記憶體配置.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">LowFree: 4320 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">承上,Low Memory除了可在High Memory空間不足時,用以配置空間外,Low Memory也可供所有Kernel/User 記憶體需求配置來源,包括Kernel Memory Management所採用的Slab/Slob/Slub,及其上的kmalloc/kmem_cache所提供的核心模塊記憶體配置,都可倚賴Low-Memory區塊進行配置.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而LowFree所表示的就是這塊Low-Memory區域所剩餘的空間,當Low-Memory記憶體不足時,對Linux Kernel來說也會是記憶體吃緊最差的狀況.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">SwapTotal: 0 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示目前系統Swap空間的總量.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SwapTotal: total amount of swap space available</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">SwapFree: 0 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示目前目前Swap空間的剩餘數量.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Dirty: 2220 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示目前有多少Page屬性為Dirty,預備寫回外部儲存裝置中.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Writeback: 0 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示正準備回寫到外部儲存裝置的記憶體大小.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">AnonPages: 256884 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">沒有實體檔案屬於Anonymous Page被映射到User-Space的記憶體大小. (=NR_ANON_PAGES)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Mapped: 90548 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">基於實體檔案被映射到User-Space Page的記憶體大小. (=NR_FILE_MAPPED),像是動態函式庫 .so/.dex 之類的檔案.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Shmem: 316 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">=NR_SHMEM</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Slab: 23176 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">Slab是Linux Kernel記憶體管理機制最基礎也是許多核心模塊所基於的記憶體分配機制,通常用於配置重要的核心資料結構或是配置實體連續的記憶體使用.通常使用Slab的方式為透過kmalloc或透過kmem_cache.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Slab記憶體空間的總和= SUnreclaim+SReclaimable</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">SReclaimable: 11952 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示可收回的Slab記憶體空間大小,例如供Cache使用的記憶體配置.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">SUnreclaim: 11224 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示不可收回的Slab記憶體空間大小.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">KernelStack: 5544 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">=global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">PageTables: 9836 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示作為Page Table使用的記憶體空間大小. (=NR_PAGETABLE)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">NFS_Unstable: 0 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示目前尚未送回到伺服器上穩定儲存裝置的NFS Pages記憶體空間大小. (=NR_UNSTABLE_NFS)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Bounce: 0 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">Bounce: Memory used for block device “bounce buffers”(=NR_BOUNCE)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">WritebackTmp: 0 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">WritebackTmp: Memory used by FUSE for temporary writeback buffers(=NR_WRITEBACK_TEMP)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">CommitLimit: 241052 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">當vm.overcommit_memory值設定為2, CommitLimit才會被致能.用以指當前系統還可以分配給應用程式使用的虛擬記憶體空間.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CommitLimit的計算會基於vm.overcommit_ratio比例的配置,計算的公式如下所示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CommitLimit = (‘vm.overcommit_ratio’ * Physical RAM) + Swap</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如系統總共有1GB記憶體搭配4GB的SWAP,而vm.overcommit_ratio配置為40 ,則CommitLimit就會等於1GB*40%+4GB=4.4GB.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(更進一步的資訊可以參考 vm/overcommit-accounting (Source Code路徑 <a href="http://hala01.com/src/linux/linux-3.5.4/HTML/S/25217.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.5.4/HTML/S/25217.html</a>))</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">Committed_AS: 7632288 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">指目前在系統中已經分配給應用程式使用的虛擬記憶體總量,包括已經分配但尚未被使用到的虛擬記憶體空間.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若一個應用程式malloc了1GB記憶體,但只實際上Touch 400MB則對應到這個Committed_AS參數則只會顯示400MB,若一個應用程式配置了1GB 記憶體並設定為Committed,則會顯示完整的記憶體空間.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
承上,當vm.overcommit_memory值設定為2,就會依據CommitLimit公式對虛擬記憶體的配置進行限制.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">VmallocTotal: 573440 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表明整體vmalloc記憶體配置區間的大小.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">VmallocUsed: 157512 kB</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示vmalloc區間被使用的空間大小.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="151">VmallocChunk: 143364 kB</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="546">用以表示vmalloc區塊(虛擬記憶體)最大可取得(Free)的連續記憶體空間.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/vmallocinfo </strong><strong>è</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
提供vmalloc/vmap的配置資訊,每一行都代表一個虛擬記憶體範圍的配置,包括</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,虛擬記憶體配置的範圍</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,配置的記憶體大小 (bytes)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Caller的名稱/資訊</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,所包含的Page個數</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,Physical Memory的位址 (phys=7fee8000)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,Callee的資訊 (像是 vmalloc,ioremap,vmap, vpages (buffer for pages pointers was vmalloced huge area)…etc)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
取決於當下實際Kernel 虛擬記憶體的配置狀況.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
實際Dump結果可參考如下內容</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">0xbf000000-0xbf042000 270336 module_alloc_update_bounds+0x14/0x64 pages=65 vmalloc<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf050000-0xbf058000 32768 module_alloc_update_bounds+0x14/0x64 pages=7 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf05b000-0xbf07e000 143360 module_alloc_update_bounds+0x14/0x64 pages=34 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf086000-0xbf0aa000 147456 module_alloc_update_bounds+0x14/0x64 pages=35 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf0b5000-0xbf0bb000 24576 module_alloc_update_bounds+0x14/0x64 pages=5 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf0be000-0xbf0de000 131072 module_alloc_update_bounds+0x14/0x64 pages=31 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf0e6000-0xbf0f3000 53248 module_alloc_update_bounds+0x14/0x64 pages=12 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf0f7000-0xbf114000 118784 module_alloc_update_bounds+0x14/0x64 pages=28 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf119000-0xbf11c000 12288 module_alloc_update_bounds+0x14/0x64 pages=2 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf11e000-0xbf120000 8192 module_alloc_update_bounds+0x14/0x64 pages=1 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf122000-0xbf129000 28672 module_alloc_update_bounds+0x14/0x64 pages=6 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf12c000-0xbf18c000 393216 module_alloc_update_bounds+0x14/0x64 pages=95 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf199000-0xbf1a0000 28672 module_alloc_update_bounds+0x14/0x64 pages=6 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf1a2000-0xbf1ad000 45056 module_alloc_update_bounds+0x14/0x64 pages=10 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf1af000-0xbf1bb000 49152 module_alloc_update_bounds+0x14/0x64 pages=11 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf1bd000-0xbf1e3000 155648 module_alloc_update_bounds+0x14/0x64 pages=37 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf1ee000-0xbf1f2000 16384 module_alloc_update_bounds+0x14/0x64 pages=3 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf1f4000-0xbf1f6000 8192 module_alloc_update_bounds+0x14/0x64 pages=1 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xbf1f8000-0xbf259000 397312 module_alloc_update_bounds+0x14/0x64 pages=96 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc004000-0xdc010000 49152 zisofs_init+0x14/0x34 pages=11 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc010000-0xdc211000 2101248 storage_logger_init+0x34c/0x564 pages=512 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc212000-0xdc214000 8192 slp_mod_init+0x34/0xb0 ioremap</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc214000-0xdc216000 8192 slp_mod_init+0x54/0xb0 ioremap</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc218000-0xdc293000 503808 mmc_blk_alloc_req+0x330/0x39c pages=122 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc293000-0xdc2a7000 81920 mt_lbprof_malloc_buf+0x2c/0x78 pages=19 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc2a7000-0xdc6b9000 4268032 mt_lbprof_malloc_buf+0x2c/0x78 pages=1041 vmalloc vpages</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc6b9000-0xdc6bc000 12288 mt_lbprof_malloc_buf+0x2c/0x78 pages=2 vmalloc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc714000-0xdc716000 8192 NewVMallocLinuxMemArea+0x8c/0x14c [nodek] vmalloc vpages</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xdc716000-0xdc71a000 16384 NewVMallocLinuxMemArea+0x8c/0x14c [nodek] vmalloc vpages</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……………….</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/slabinfo </strong><strong>è</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以顯示Kernel Slab Memory Pool資訊,Linux Kernely採用Slab/Slob/Slub作為核心記憶體的管理機制,而slabinfo可用以顯示Kernel Memory Cache物件使用的狀態,如下為筆者以Slub為例,並在系統啟動後透過/proc/slabinfo所顯示的Kernel Memory Cache使用狀態.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
包括像是檔案系統,TCPIP通訊層,kmalloc所要配置使用的記憶體區塊 (kmalloc-8192,kmalloc-4096,kmalloc-2048,kmalloc-1024,kmalloc-512,kmalloc-256,kmalloc-192,kmalloc-128,kmalloc-96 kmalloc-64,kmalloc-32),都會記錄在slabinfo中,可藉此了解核心記憶體配置當下的狀況.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">slabinfo – version: 2.1<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ext4_groupinfo_4k 34 34 120 34 1 : tunables 0 0 0 : slabdata 1 1 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
RAWv6 19 38 832 19 4 : tunables 0 0 0 : slabdata 2 2 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
UDPLITEv6 0 0 832 19 4 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
UDPv6 19 38 832 19 4 : tunables 0 0 0 : slabdata 2 2 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
tw_sock_TCPv6 0 0 160 25 1 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
TCPv6 0 0 1504 21 8 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
nf_conntrack_c0b175a0 0 0 240 17 1 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kcopyd_job 0 0 2952 11 8 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dm_uevent 0 0 2464 13 8 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dm_rq_clone_bio_info 0 0 8 512 1 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dm_rq_target_io 0 0 248 16 1 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cfq_io_cq 1346 1387 56 73 1 : tunables 0 0 0 : slabdata 19 19 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fuse_request 0 0 400 20 2 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fuse_inode 0 0 544 15 2 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
isofs_inode_cache 17 17 456 17 2 : tunables 0 0 0 : slabdata 1 1 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fat_inode_cache 5850 5850 536 15 2 : tunables 0 0 0 : slabdata 390 390 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fat_cache 184 340 24 170 1 : tunables 0 0 0 : slabdata 2 2 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jbd2_transaction_s 26 50 160 25 1 : tunables 0 0 0 : slabdata 2 2 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jbd2_revoke_record_s 128 128 32 128 1 : tunables 0 0 0 : slabdata 1 1 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
journal_handle 170 340 24 170 1 : tunables 0 0 0 : slabdata 2 2 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
revoke_record 256 256 16 256 1 : tunables 0 0 0 : slabdata 1 1 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ext4_inode_cache 1763 1764 760 21 4 : tunables 0 0 0 : slabdata 84 84 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ext4_free_data 102 204 40 102 1 : tunables 0 0 0 : slabdata 2 2 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ext4_allocation_context 36 72 112 36 1 : tunables 0 0 0 : slabdata 2 2 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ext4_prealloc_space 53 92 88 46 1 : tunables 0 0 0 : slabdata 2 2 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ext4_io_end 182 196 576 14 2 : tunables 0 0 0 : slabdata 14 14 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ext4_io_page 5120 6144 8 512 1 : tunables 0 0 0 : slabdata 12 12 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ext3_inode_cache 0 0 616 13 2 : tunables 0 0 0 : slabdata 0 0 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
………</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Proc FileSystem Memory Control Information</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除了前述屬於資訊類的Memory Proc File System操作外, Kernel Memory還幫開發者預備好可供控制的各類參數,了解這些參數的入門障礙,絕對會比從眾多Kernel Memory Soure Code去整理邏輯來的好上手,這也是對Kernel Memory管理有興趣的開發者很適合的入門基礎.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為在筆者Linux Kernel 環境下,透過System Control Tool “sysctl” 所顯示出當下所有System Control Information 的數值</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">sysctl -a|more<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_child_runs_first = 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_min_granularity_ns = 3000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_latency_ns = 15000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_wakeup_granularity_ns = 3000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_shares_ratelimit = 750000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_tunable_scaling = 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_shares_thresh = 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_features = 15834235</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_migration_cost = 500000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_nr_migrate = 32</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_time_avg = 1000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.timer_migration = 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_rt_period_us = 1000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_rt_runtime_us = 950000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.sched_compat_yield = 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.panic = 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.exec-shield = 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.core_uses_pid = 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel.core_pattern = core</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…………………….</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在Android 4.1.1 r1下,則可以透過 “system/core/rootdir/init.rc” (<a href="http://hala01.com/src/android/android-4.1.1_r1/HTML/S/4180.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/android/android-4.1.1_r1/HTML/S/4180.html</a>)檢視如下內容</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">write /proc/sys/kernel/panic_on_oops 1<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/hung_task_timeout_secs 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/cpu/alignment 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/sched_latency_ns 10000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/sched_wakeup_granularity_ns 2000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/sched_compat_yield 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/sched_child_runs_first 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/randomize_va_space 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/kptr_restrict 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/dmesg_restrict 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/vm/mmap_min_addr 32768</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/sched_rt_runtime_us 950000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/sched_rt_period_us 1000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/vm/overcommit_memory 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/vm/min_free_order_shift 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/vm/dirty_expire_centisecs 200</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/vm/dirty_background_ratio 5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在沒有移植sysctl的環境,就可以參考Android init.rc中的作法,可以透過自行Script echo值的方式對System Control數值進行調教動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Memory System Control Information的資訊還可以透過 /proc/sys/vm目錄下的File Node來取得,如下筆者根據 /proc/sys/vm 目錄下不同的File Node進行說明與範例.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/block_dump</strong><strong>è</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在筆者的裝置上預設為0 (也就是步開啟 Block I/O Debugging),若設定為非0值就表示開啟Block I/O Debugging機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/compact_memory </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當Linux Kernel編譯時設定CONFIG_COMPACTION,就可以開啟Kernel Memory支援Compact Memory 機制的能力,若設定此File Node值為 ”1” 時,所有的Memory Zone都會致能Compaction能力,讓原本隨著Kernel執行時間越長,會越來越破碎的Free Memory 區塊可以有機會被整合在一起成為連續的Block,讓Linux Kernel有機會配置較大塊的實體連續記憶體.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/dirty_background_bytes and</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/dirty_background_ratio </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以參考Linux Kernel 3.5.4中 mm/page-writeback.c的代碼,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dirty_background_ratio值預設為 10,也就是當Drity Page達到總系統記憶體10%時,就會觸發 Kernel Background WriteBack Thread “pdflush” 進行回寫流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dirty_background_bytes用以表示當Dirty Page Memory達到多少Bytes時,會觸發pdflush daemon背景執行Write-Back的行為. 同樣的, dirty_background_ratio則用以表示當Dirty Page Memory比率達到總系統管理Memory比率多少時,會觸發pdflush daemon背景執行Write-Back.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
兩者只有一個會啟作用,當dirty_background_ratio致能時,就會導致另一個數值dirty_background_bytes變為0,以筆者的CentOS主機而言, dirty_background_bytes為0,而dirty_background_ratio為10,也就是說當Dirty Page Memory佔系統可管理的Memory比率達到10%時,就會觸發pdflush daemon進行Write-Back回寫的操作.而在Android 4.1.1_r1下, dirty_background_ratio被設定為5,也就是說,只要有5%的Dirty Page,在Android手機上就會觸發pdflush 回寫的機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/dirty_bytes and</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/dirty_ratio </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可參考Linux Kernel 3.5.4中 mm/page-writeback.c的代碼,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vm_dirty_ratio值預設為 20,也就是當Drity Page達到總系統記憶體20%時,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就會觸發Kernel Page Write-Back的程序.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dirty_bytes用以表示當Dirty Page Memory達到多少Bytes時,會觸發Page強制Write-Back的行為. 同樣的, dirty _ratio則用以表示當Dirty Page Memory比率達到總系統管理Memory比率多少時,會觸發Page強制Write-Back.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當第一次看到 dirty_background_ratio 與 dirty_ratio時,當下各位可能會想明明都是針對Dirty Page的WriteBack行為,為何會有兩種水位與兩種行為同時存在系統中呢? 其實參考mm/page-writeback.c的代碼時,就可以發現dirty_ratio是屬於強制性的回寫,也就是說當一個Memory Zone內的Dirty Page達到這個比例時就會觸發Kernel Memory Management把Dirty Page強制回寫的流程,但dirty_background_ratio是屬於較軟性的行為,因為這是透過pdflush kernel thread進行的流程,可以在背景執行對這些Dirty Page回寫,並不會因此影響到當下正在執行中的Process. 所以看Linux Kernel中預設的水位是Dirty Page達到10%的比例時就會先透過pdflush kernel thread進行回寫,當Dirty Page達到20%比例時,就等於是一個很嚴重的狀況,此時就會在balance dirty page流程中觸發強制的Write Back,讓系統可以回復到原本預設合理的狀態.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/dirty_expire_centisecs </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以表明一個Dirty Page多久算是 “Expire”, 例如在筆者的CentOS上此值為3000 (也就是30秒算是Expire),而在我的Android手機上此值為100(也就是1秒算是Expire),當系統存在的Dirty Page ”時間週期”超過這個”Expire”數值時,就會在下次pdflush kernel thread被喚醒時,被回寫到儲存裝置中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若此值設定太低,也就間接導致回寫儲存裝置會較為頻繁,需依產品當下的需求而定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/dirty_writeback_centisecs </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以設定pdflush kernel thread多久執行一次,單位為1/100秒,例如在筆者的CentOS上此值為500 (也就是每5秒一次),而在我的Android手機上此值為300(也就是每3秒一次),通常如果所在環境記憶體比較充裕,且對執行檔案寫入的應用需求較低,而此值適合增加,但若記憶體的總量低或對檔案寫入的需求與頻繁度高,而降低這個值,會讓pdflush比較頻繁也均勻化Dirty Page Write-Back的行為.(可以更頻繁的分散到不同的時間間隔中)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/drop_caches </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過drop_caches可用以支援檔案系統相關的Cache 清除機制,例如像是</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,</strong><strong>如果要釋放File</strong><strong>的PageCache:</strong> 就可以透過 echo 1 到這檔案中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,</strong><strong>如果要釋放檔案系統的Dentries</strong><strong>與Inodes: </strong>就可以透過 echo 2到這檔案中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3,</strong><strong>如果要同時釋放File PageCache</strong><strong>與檔案系統的Dentries</strong><strong>與Inodes</strong>: 就可以透過 echo 3到這檔案中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關釋放Cache Memory的操作並不包含尚未回寫到儲存裝置的Dirty Page,要能一併有效反應並釋放出更多的記憶體空間,可先透過指令 “sync” 強制讓Cache Memory回寫到儲存裝置中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/extfrag_threshold </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
extfrag_threshold值預設為500,這值的設定會影響到Kernel Compaction Memory的行為,而這值會發揮作用的前提也是Linux Kernel Memory Compaction機制有被致能.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當” fragmentation index is <= extfrag_threshold”成立,則Compact Memory流程將不會被執行,也就是說如果extfrag_threshold為0,則表示上述條件式不會成立,也就表示Kernel會很積極的進行Memory Compaction,也就是說當此值為0,但卻又配置不到連續的記憶體時,就表示Kernel Memory 當下真的是處於記憶體不足的狀況.反之,如果此值為1000,則Linux Kernel Memory Compaction會處於非常不積極的狀態,此時如果配置記憶體失敗,就有很大可能是因為Linux Kernel Memory當下Fragment 狀況所引起的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/hugepages_treat_as_movable </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
hugepages_treat_as_movable值預設為0,當被設定為非0值時就表示允許從ZONE_MOVABLE Memory 區塊進行大塊(Huge Page)的記憶體配置.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Movable Zone主要用於配置可以被Reclaim或Move的Kernel Page,像是大區塊的記憶體配置(Hugh Pages)預設就不會從這區塊記憶體進行配置,但若是設定hugepages_treat_as_movable為非0值,就表示系統許可大區塊的記憶體配置可以從Movable Zone中進行配置(Depend on nr_hugepages). 但若應用程式使用大量的mlock (Memory Lock)配置所取得的Memory Page,就會導致Movable Zone不容易發揮對應的效益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在初始化時會把所傳入的kernekcore記憶體數字根據系統有多少Memory Node平均分配給不同的Memory Node. 最後並會透過巨集roundup,計算MOVABLE ZONE 包含Pages的數值,並確保不會小於MAX_ORDER_NR_PAGES 的Page個數,而MAX_ORDER_NR_PAGES通常為 Order 10,也就是不小於1024個Pages.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除了kernelcore參數外,並支援kernelcore_max_addr用以限定因kernelcore設置後所配置的kernelcore最大的記憶體位置(在這範圍內的記憶體位址都是Non-Movable),在kernelcore_max_addr位址以上的記憶體Page都會是屬於 Movable/Migratable.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在沒有指定kernelcore參數的核心中,則不會有 ZONE_MOVABLE記憶體區段產生.當Kernel傳入的Parameters有包括kernelcore,則會透過函式cmdline_parse_kernelcore去解析核心啟動時所傳入的kernelcore帶的數值,這數字用以表示Linux Kernel支援non-movable allocation的記憶體總量,並會Applied這參數到系統中有致能”High Memory Zone”的 Memory Node上.而對每一個Memory Node而言,在這數值範圍以外的記憶體就會是屬於Movable Pages.(多數的手持裝置或購買的桌上型電腦都是只有一個Memory Node.).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/hugetlb_shm_group</strong> <strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
包含許可產生支援hugetlb page的System V Shared Memory區段的Group ID.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/laptop_mode </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關laptop_mode的說明最佳文件就是Linux Kernel Source Code中的 “Documentation/laptops/laptop-mode.txt” 檔案,主要用以針對筆記型電腦的配置所支援的設定參數,所屬的系統參數設定檔可以參考”/etc/sysconfig/laptop-mode”,像是最後剩餘的電量還能使用多久,就要強制關係Laptop Mode,Process Dirty Page,或有關儲存系統的配置參數…etc.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/legacy_va_layout </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
預設值為0,若設定為非0值,會把目前32-bits MMAP Layout設定為原本2.4 Kernel的Process MMAP Layout. (筆者目前無2.4環境,尚無法比對跟Kernel 3.x的差異…..Orz).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/lowmem_reserve_ratio </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在筆者的Android裝置上,若為DMA or DMA32 Zone此值預設值為 256,其它則是預設為 32 (例如,Normal Zone),對Linux Kernel而言,通常User-Space記憶體的取得會先從High Memory Zone取,若無才會往Low Memory Zone取,主要原因在於Kernel重要的資料結構 (based on kmalloc/kmem_cache),都會從有限的Low Memory空間挖取,若User-Space記憶體配置也先從Low Memory 空間挖取記憶體設定mlock, 就會導致Low Memory 空間越來越難以回收</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於上述說明,可以知道lowmem_reserve_ratio 比較適用於平台上有大塊High-Memory Zone的配置,若使用者裝置尚僅有Low Memory Zone,或是High Memory Zone也很有限 (例如只有幾十MB),其實設定這個參數的意義也不會太大.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關計算的方式可以參考Linux Kernel 3.5.4函式 setup_per_zone_lowmem_reserve (in Source Code mm/page_alloc.c, 線上Source Code in <a href="http://hala01.com/src/linux/linux-3.5.4/HTML/S/8040.html#L4996" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.5.4/HTML/S/8040.html#L4996</a>), 基於lowmem_reserve_ratio與Present Page所計算的Zone Protetion邏輯如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">(i = j):<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(should not be protected. = 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(i < j):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
zone[i]->protection[j]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
= (total sums of present_pages from zone[i+1] to zone[j] on the node)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/ lowmem_reserve_ratio[i];</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(i > j):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(not necessary, but looks 0)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於lowmem_reserve_ratio會以Array的方式呈現目前系統中每個Zone的參數,以筆者手中的裝置來說,在Buddy System包括如下內容的環境</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">Node 0, zone Normal 488 144 73 14 7 1 2 0 0 0 0<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone HighMem 16 2 1 1 1 0 0 0 0 0 0</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lowmem_reserve_ratio Array內容為 “32 32”,且</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">Zone Normal, present=112268 and protection: (0, 349, 349)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Zone HighMem, present=11176 and protection: (0, 0, 0)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於計算邏輯,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Zone Normal的protection: (0, 349, 349)是以</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
A, (i = j), protection=0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
B, (i < j), protection=11176/32 = 349.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
C,(i < j) , protection=11176/32 = 349.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
計算所得.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在64bits Linux Kernel 上的Buddy System包括如下內容的環境 (請注意這是64bits的裝置,雖然記憶體有16GB,但卻不會有High-Memory Zone)</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">Node 0, zone DMA 2 0 1 2 1 1 0 0 1 1 3<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone DMA32 9150 8854 8318 7520 6130 4201 2203 723 146 11 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Node 0, zone Normal 8660 6230 5741 19059 14697 6314 2367 496 48 4 0</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lowmem_reserve_ratio Array內容為 “256 256 32” ,且</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">Zone DMA, present=3809 and protection: (0, 2914, 16042, 16042)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Zone DMA32, present=746212 and protection: protection: (0, 0, 13128, 13128)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Zone Normal, present=3360775 and protection: (0, 0, 0, 0)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於計算邏輯,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Zone DMA的protection: (0, 2914, 16042, 16042)是以</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
A, (i = j), protection=0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
B, (i < j), protection=746212 /256 = 2914.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
C,(i < j) , protection=(746212 +3360775 )/ 256 = 16042.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
D,(i < j) , protection=(746212 +3360775 )/ 256 = 16042.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Zone DMA32的protection: (0, 0, 0, 13128, 13128)是以</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
A, (i > j), protection=0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
B, (i = j), protection=0.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
C,(i < j) , protection=(3360775 )/ 256 = 13128.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
D,(i < j) , protection=(3360775 )/ 256 = 13128.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
計算所得.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於lowmem_reserve_ratio所計算的Protection數值可用以決定是否一個Memory Zone適合用於記憶體配置或是應該要進行Memory Reclaimed流程了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當要進行記憶體配置時就會先到當下對應Zone ID (此區也會是Protection數值為0的區塊)進行配置,若當下對應的Zone ID已經沒有足夠的Free Page可供使用,此時就可以往下一個Zone ID去找Free Page嘗試配置出足夠的記憶體空間,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以DMA32的例子來說,所以DMA32 Zone的Free Page並不足夠因應這次所需的記憶體配置需求,Kernel就會取得下一個Normal Zone (ID=2) 的Free Page數值,並且確認該Memory Zone的 <strong>“Free Page</strong><strong>數量大於 watermark[WMARK_HIGH] + 13128 (=DMA32 Zone->Protection[2])”,</strong>若是則可將DMA32所需記憶體透過Normal Zone進行記憶體配置.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也就是說,若希望確保Normal Zone盡可能不要被其它需求給配置走,就該把 lowmem_reserve_ratio設定為1 (=100%),若是設定的數值越高,則DMA32 Zone->Protection的數值計算後越低,則越有機會讓Normal Zone提供記憶體給DMA32 Zone.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/max_map_count </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
MMAP是Linux環境上記憶體配置(dlmalloc mmap)與應用程式執行所需Shared Library 與 DEX檔案Mapping最頻繁使用的介面.而max_map_count能用以限定單一應用程式執行環境最大的MMAP數量,預設值會等於DEFAULT_MAX_MAP_COUNT,而在筆者驗證的Android手機上此值預設為65530.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於目前Android上的dlmalloc/mspace記憶體管理機制,包含檔案執行MMAP的需求,除非有Resource Leakage的問題發生,預設值的配置已能符合目前應用程式的需求.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/memory_failure_early_kill </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel Memory Failure保護機制 (Source Code in mm/memory-failure.c),原本用意是在支援有記憶體ECC保護機制下,透過硬體回報特定的Memory Page有問題時,透過Page Poison Bit提供一個 “Soft Offline”機制,避免讓有問題的Page導致程式執行錯誤發生.在執行時期也可以透過SetPageHWPoison設定一個Page為Hardware Poison,或可透過PageHWPoison巨集確認是否所處理的Page已經被設定為Hardware Poison.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memory_failure_early_kill預設為0,可用以設定當Memory Page被Hardware報錯誤時,要如何處理當下Process運作的行為. 通常,如果所損壞的Page可以在儲存裝置上找到的話,Kernel 是有機會可以補救的,但若該損壞的內容是Run-Time執行</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
過程中產生的,除非結束Process執行,不然會非常難以補救.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,列出memory_failure_early_kill設定數值與對應的處理行為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0: 在偵測到Page損壞後,會把該Page 從所有使用到他的程式記憶體空間中Unmap掉,並只有在後續仍嘗試去使用該Page的程式會被結束執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1: 在偵測到Page損壞後,會結束包含該無法修復Page的所有程式執行. (只限於User-Space的應用程式,若是Kernel Space的Memory Page則無法補救.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
結束User-Space程式的方式為透過SIGBUS (Signal No. 7 with Signal Code=5, BUS_MCEERR_AO in include/asm-generic/siginfo.h). 若程式處理流程有需要攔截這動作,則可另外處理.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而Hardware Poison機制只限定於有支援Memory ECC的硬體上,若所使用的平台並沒有這樣的能力,則無這樣的支援.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/memory_failure_recovery </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memory_failure_recovery預設為1,如同memory_failure_early_kill,這是一個基於Hardware Poison的機制,可用以設定Memory Failure Recovery的行為,當設定為1表示會嘗試進行修復,反之設定為0則表示一定遇到Memory Failure就會觸發Kernel Panic 並顯示 “Memory failure from trap …. on page ….” Kernel 字串.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/min_free_kbytes </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在筆者測試的Android環境中, min_free_kbytes值預設為2680,此值主義用來強制Linux Kernel所要保留的最低Free Memory總數. 而這個值也會被用來計算為當下Kernel Memory Management中的 Min WaterMark水位 (=watermark[WMARK_MIN]).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若此值設定的太高,會更容易在進入Reclaim Pages時,導致觸發OOM (Out-Of-Memory) 流程,反之若設定的過低,例如只有幾百kbytes,就有機會導致Kernel Memory 的Allocation與Reclaim流程,在系統陷入極低Free Memory狀態下,陷入Deadlock的狀況. (在配置記憶體時,又會進入Reclaim Page,與進入OOM,隨後又執行記憶體配置,如此不斷反覆觸發,導致系統Deadlock無法有效運作.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/min_slab_ratio </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
min_slab_ratio預設為5,並只在支援 NUMA(Non-Uniform Memory Access Architecture)的Linux Kernel才支援這個選項, 並會被用以計算Memory Zone的min_slab_pages數字,若目前Memory Zone內可被Reclaim的Slab Page總數大於min_slab_pages,就會觸發Shrink Slab流程,直到釋放足夠的記憶體為止.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/min_unmapped_ratio </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
min_unmapped_ratio預設為1,並只在支援 NUMA(Non-Uniform Memory Access Architecture)的Linux Kernel才支援這個選項, 並會被用以計算Memory Zone的 min_unmapped_pages數字,若Unmapped Pages超過這數值,會導致zone_reclaim_mode設定為1,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/mmap_min_addr </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mmap_min_addr 的設定是在Linux Kernel 2.6.23之後導入的機制, 用以指定User-Space可以MMAP的最低記憶體位址,在Jelly Bean之後這個數值被設定為32768.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
主要目的為避免非特權等級的使用者行程在非許可的低記憶體位址空間中產生記憶體映射,而發生Linux潛在的安全問題發生(像是跳到鄰近0×00000000附近的記憶體位址執行程式碼或讀取資料).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/nr_hugepages </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以設定hugepage pool的最低許可值.(相關文件可參考 Documentation/vm/hugetlbpage.txt).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/nr_overcommit_hugepages </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以設定hugepage pool的最大值,一個系統的上限為 “nr_hugepages + nr_overcommit_hugepages”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/nr_pdflush_threads </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這是一個唯讀的設定,用以顯示目前系統有多少pdflush kernel thread被啟動用以把Dirty Page回寫到儲存裝置中.一個系統的pdflush kernel thread上限可以透過nr_pdflush_threads_max進行設定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/nr_trim_pages </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
nr_trim_pages只在關閉 MMU 時才有作用 (CONFIG_MMU=n),當數值為0表示Disable,若設定為1表示在NO-MMU環境下MMAP超過2^1的記憶體配置都會被裁剪,參考函式do_mmap_private (in Source Code mm/nommu.c),若設定為>=1,則會依據所設定的值,以power-of-2進行Page Size Aignment. (例如設定為3既是超過2^3=8個Pages就會被裁剪.).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/numa_zonelist_order </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
numa_zonelist_order預設為” default”,並只在支援 NUMA(Non-Uniform Memory Access Architecture)的Linux Kernel才支援這個選項.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在進行記憶體配置時,跨不同Memory Zone之間的記憶體配置會根據Zone List順序來加以決定,例如要配置GFP_KERNEL屬性的記憶體時,找尋Memory Zone的順序會是 ZONE_NORMAL -> ZONE_DMA,也就是說當Normal Zone記憶體不足時,就會嘗試透過DMA Memory Zone來尋找是否有可供使用的記憶體區塊大小.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
假設在一個平台上支援兩個Memory Node,而這兩個Memory Node各自都擁有Normal Zone與DMA Zone,則找尋記憶體的順序可以為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
方案1, Normal Zone in Node(0) -> DMA Zone in Node(0)->Normal Zone in Node(1)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
方案2, Normal Zone in Node(0) >Normal Zone in Node(1)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-> DMA Zone in Node(0)-</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
與效能而言,當Node 0的Normal Zone被使用完畢,取同一個Node 0上的DMA Zone的記憶體對效能上會是比較好的,但缺點卻在於會讓在Node 0上原本相對Size就比較小的DMA Zone被Normal Zone的需求給加速耗盡. 但如果選擇方案2,會因為要跨越Node 0->Node 1而導致效能的影響,當然好處是可以透過兩個Memory Node的Normal Zone配置避免因為記憶體不足的問題把要給硬體傳輸使用的DMA Zone也給加速耗盡. (通常,Normal Zone都會比DMA Zone大上不少).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而方案1在此可稱呼為 “Node-Order”,方案2可稱呼為 “Zone-Order”,兩者思維差異在前者是先把自己Node上的記憶體耗盡後才往其它Memory Node去找,後者則是依據不同Memory Node上的Zone屬性來最佳化記憶體的使用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在系統啟動後可以透過 “echo Z > /sys/vm/numa_zonelist_order”啟動 Zone-Order ,透過“echo N > /sys/vm/numa_zonelist_order” 啟動 Node-Order,若是執行 “echo D > /sys/vm/numa_zonelist_order” 啟動 Default-Order則預設會是以Node-Order來執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/oom_dump_tasks </strong><strong>è</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
oom_dump_tasks設定為0,則關閉這機制,若設定為1表示機制開啟.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可在Out-Of-Memory 發生時Dump Task包括User/Kernel-Space Process/Thread的資訊,也就是說當Kernel在記憶體不足時,觸發OOM (Out-Of-Memory)去結束程式執行時,可以把包括 PID,UID,TGID,VM Size,RSS,CPU, OOM_ADJ Score與 Process Name 等資訊Dump出來,讓系統問題的解決時,可以有足夠的資訊進行分析問題會遇到記憶體不足的問題. (可能是Memory Leakage 亦或者是該應用程式特殊的設計行為).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/oom_kill_allocating_task </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
oom_kill_allocating_task預設為0,可用以關閉或開啟OOM (Out-Off-Memory)在記憶體不足時,進行Process結束執行的能力.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若此值為0,OOM Process Killer會在記憶體不足時Scan Task-List並針對所選出的Process進行結束執行的動作.(通常會選擇佔據記憶體最大的那個Task,以便在刪除時可以儘快釋出足夠的記憶體空間).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若設定為非0值,則不會去Scan Task-List只會結束觸發OOM狀況的Process.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此外,若panic_on_oom也有致能,Kernel Panic優先級會高於oom_kill_allocating_task所做的設定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/overcommit_memory </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
overcommit_memory預設值為 0 (=OVERCOMMIT_GUESS),是用於控制User-Space 記憶體的配置是否可以Overcommit,影響的行為在於裝置上的Memory總數不足時,是否可以讓應用程式進行超過記憶體總量的配置,等到真的去Touch到過量的記憶體時,才做異常行為的處理. (可參考文件 Documentation/vm/overcommit-accounting, in <a href="http://hala01.com/src/linux/linux-3.5.4/HTML/S/25217.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://hala01.com/src/linux/linux-3.5.4/HTML/S/25217.html</a>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若此值為0 (=OVERCOMMIT_GUESS),表示當User-Space一用程式要配置新的記憶體時,Kernel會去計算目前剩下的Free Memory是否足夠,才提供服務,若所在的環境有開啟Swap的話,就可以透過Swap-Device裝置,讓User-Space Page-Reclaimable 的記憶體有機會被Swap-Out到外部裝置上,從而讓整體可供使用的記憶體空間更大. (筆者使用的Linux Server就是設定為 0 + Swap-Device.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若此值為1 (=OVERCOMMIT_ALWAYS),Kernel會假設記憶體永遠足夠,並許可User-Space 記憶體Overcommit,直到實際使用異常發生才做錯誤處理或預防. 筆者使用的Android裝置就使設定此值為1,但由於Android有支援Low-Memory Killer 機制,雖然設定此值為1,且絕大多數Android裝置都不會開啟Swap-Device,但並不會真的發生記憶體耗盡的問題. 除非有Kernel Space or ADJ權值很大的Process發生Memory Leakage,不然在進入到記憶體最差的狀況前,Low-Memory Killer機制就會運作刪除ADJ權值較低的Process,藉此釋放出更多的記憶體空間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若此值為2 (=OVERCOMMIT_NEVER),則還須參考overcommit_ratio的設定值,表示 “Don’t overcommit”, 總體可使用的記憶體空間會等於 Swap裝置的大小 + Physical Memory Size * overcommit_ratio (預設為50%) ,Kernel會避免任何Overcommit記憶體的行為發生,也就是說若程式能配置到記憶體,就可以保證一定有對應的空間 (不論是來自Swap or Physical Memory)可以提供給程式使用,若會發生錯誤就是在記憶體配置時失敗,而不會說配置之後,才在Run-Time實際使用時,觸發Page Fault,但又無法找到可用的Memory Page,而導致在執行過程中的錯誤發生.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這配置對於設計Embedded System而言很有幫助,可藉此決定Memory釋出機制,並影響到最終產品的運作行為.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而當下Memory Commit的資訊可以透過/proc/meminfo中的CommitLimit與Committed_AS得知. (overcommit limit and amount committed).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如下面為筆者的Android手機,設定為OVERCOMMIT_ALWAYS,可以看到實際Commit的記憶體上限跟</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CommitLimit: 241052 kB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Committed_AS: 7632288 kB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如下面為筆者的Linux Server,設定為OVERCOMMIT_GUESS,可以看到實際Commit的記憶體上限跟</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CommitLimit: 24573564 kB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Committed_AS: 1468016 kB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關記憶體屬性與Overcommit計算的原則如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232"><strong>來源分類</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232"><strong>記憶體屬性</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232"><strong>說明</strong></td></tr>
<tr><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">File backed map<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(也就是有實體存在的檔案Memory Mapping)</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">Shared或Read-Only</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">不納入成本的計算</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">PRIVATE WRITABLE</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">依實際Mapping的範圍與Instance個數計算成本</td></tr>
<tr><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">Anonymous Memory 或來自 /dev/zero 的Memory Mapping</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">PRIVATE READ- Only</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">不納入成本的計算</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">PRIVATE WRITABLE</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">依實際Mapping的範圍與Instance個數計算成本</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">SHARED</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="232">以Mapping的範圍計算成本,但並不因Mapping的Instance變多而增加成本計算</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其它影響計算成本的操作還有</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">1, Memory Mapping Page因為Copy-On-Write而產生出新的複製Page</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">2, 透過mprotect設定Page屬性為 Commit</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">3, 透過mremap改變Memory Mapping大小</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">4, 透過BRK (改變Data Segment大小)所配置的記憶體</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">5, 執行 munmap釋放記憶體</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">6, shmfs memory drawn from the same pool (SHMfs accounting)</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/overcommit_ratio </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
overcommit_ratio設定只在overcommit_memory設定為2(=OVERCOMMIT_NEVER)時才有作用,用以計算SWAP + Physical Memory * overcommit_ratio 得到系統總體可供Commit的記憶體總量.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/page-cluster </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以控制要把Memory Pages回寫到SWAP上的Pages數量與影響SWAP I/O操作. 會以power-of-2的方式表示,也就是說如果設定為0表示一次以一個Page為單位進行SWAP 處理,若設定為 1表示一次2個Page. page-cluster預設為3,也就是會一次以2^3=8個Pages處理Pages SWAP操作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在系統效能調教時,就可根據自身產品對 I/O的配置,進行細部調整.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/panic_on_oom </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可用以致能在OOM (Out-Of-Memory)發生時,觸發Kernel Panic. panic_on_oom預設值為0,Linux Kernel在OOM發生時,會透過oom_killer嘗試結束Process並釋放出足夠的記憶體讓系統可以持續運作下去.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果設定為1,原則上當OOM發生時就會導致Kernel Panic,但若當下系統還有其它的Memory Node擁有Free Memory,只是這個Process受限於Memory Policy/CPUSets而導致無法透過其它Memory Node取得可供使用的記憶體空間,表示OOM的狀況並非系統當下已經沒有記憶體,而是受限於程式本身與系統配置的問題,此時就會透過oom_killer刪除程式釋放出足夠的記憶體,而不會讓系統進入Kernel Panic狀態,以免影響到其它Process的正常執行. (此時系統其它Process還是可以透過有Free Memory的Memory Node取得記憶體空間).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果設定為2,一旦OOM發生,就會觸發Kernel Panic讓整體系統停下來,通常這樣激烈的手段,應該是用在開發過程中,希望透過觸發Kernel Panic + KDump進行除錯的需求.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/percpu_pagelist_fraction</strong><strong>è</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始值為0,表示Linux Kernel 預設不會用這個值作為設定Memory Zone Per CPU Page List High Water Mark的參數.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以決定在每個Memory Zone中的per_cpu_pages->High_WaterMark 所佔的比例.最小值為8,用以表示不允許有超過1/8的Memory Zone所屬Page被配置給任意的Per CPU Page List.若設定為100,就表示Memory Zone內最多只能有1/100的Page是配置給Per CPU Page List.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/stat_interval </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以設定Virtual Memory統計資料 (VM Statistics)更新的週期,預設值為1.(也就是1秒.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/swappiness </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
預設值為60,用以決定Kernel 會有多努力要把記憶體中的資料Swap Out到外部儲存裝置中,數值越高會越積極的去執行Swap Out.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/vfs_cache_pressure </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以決定Kernel Reclaim 檔案系統目錄/inode object Cache的積極性, vfs_cache_pressure預設為100,表示Kernel會試圖在考量到PageCache/SwapCache平衡的前提,去對dentries/inodes Cache Memory進行Page Reclaim的操作. 如果降低這個數值,會讓Kernel盡可能的保留dentries/inodes Cache Memory,缺點也就是會讓記憶體耗用的速度更快,反之如果這個數值大於100,就會讓Kernel 更積極的對dentries/inodes Cache Memory進行Reclaim的回收操作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/proc/sys/vm/zone_reclaim_mode </strong><strong>è</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
zone_reclaim_mode可提供當Memory Zone記憶體耗盡時,對Memory Reclaim積極性的增減操作. 若此值設定為0,表示不會以Zone Reclaim的動作發生,所有的記憶體配置會進一步嘗試從同一個Node中的其它Zone,或是從其它Node取得Free Memory. (需視當下numa_zonelist_order的設定為何).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關zone_reclaim_mode的各Bit 意義說明如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Bit 0 : 為1表示Memory Zone Reclaim Enable</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Bit 1: 為1表示Zone reclaim writes dirty pages out</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Bit 2: 為1表示Zone reclaim swaps pages</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若所提供的服務是檔案伺服器,則並不建議打開Zone Reclaim機制,以便儘可能在記憶體中保留File System有關的Cache Memory,提昇系統的效能. 當觸發的Zone Reclaim是涉及到其它Memory Nde上的Dirty Page Write Out,則可能會對當下執行這動作的處理器Processes有效能上的影響.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文主要闡述筆者認為基礎,並補上Linux Kernel Memory在 /proc 下所提供的記憶體資訊與控制機制,若對於這些資訊與控制參數有興趣,在閱讀後各位也可以使用自己所擁有的Android/Linux執行環境加以驗證 (嗯嗯,,不過記得要先Root.),唯有親手操作過,體驗過,本文所提到的內容才有機會真正內化為未來可供使用的開發利器.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後,核心記憶體管理機制是一個看似簡單,卻又複雜的議題,Linux Kernel Memory然在持續演進中,希望本文能對各位Hacking Kernel Source Code的路上有所助益. Thanks!.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-30095691998244436212017-06-04T10:03:00.000-07:002017-06-04T10:03:07.878-07:00Android 4.1 Jelly Bean安全機制探討<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android 4.1 Jelly Bean安全機制探討</h1>
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android 4.1 Jelly Bean安全機制探討</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
By loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<a href="mailto:hlchou@gmail.com" style="color: #666666; font-weight: bold; text-decoration-line: none;">hlchou@gmail.com</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關手機或作業系統的安全議題一直就像是潘朵拉的盒子一樣,帶點神祕但卻又很吸引大家的目光.由於智慧型手機幾乎是現代人必備的隨身電子產品,若在智慧型手機上被找到安全漏洞,相對於原本個人電腦的世界,所引起的漣漪也將非比尋常.曾在<strong>“</strong><strong>我是亞桑傑”</strong>這本書中讀到如下印象深刻的話語</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
”我憎恨對安全的歸類,他們的分類就是,<strong>’</strong><strong>凡是沒有被明確允許就是不准’</strong>,他們以為他們是誰? 想用科技來掩護他們野蠻的行為.”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
熟悉安全技術的演進,可讓我們除了理解系統核心外,還多了不同看系統的角度.或許有天,真有那樣的機會,這些安全技術真的可以幫助到各位當下所需解決的棘手難題也說不定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Jelly Bean可說是目前為止,最安全的Android作業系統</strong>.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先,本文將著重在Android 4.1 Jelly Bean中新增的安全機制,而討論Android安全議題最佳的入口網站是Google的網頁 “Android Security Overview” (<a href="http://source.android.com/tech/security/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://source.android.com/tech/security/</a>),在這網頁中有說明過去以來每一版本Android在安全Features上的差異點,對Android安全議題有興趣的開發者,絕對不可以錯過.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
總結來說,Android主要的安全特徵演進簡述如下表</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 815px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">Android版本</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="662">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">1.5之後</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="662">1,加上Stack Overflow Protector的編譯器選項 -fstack-protector,可在程式碼編譯過程中,在函式進入與離開時,檢查所加上的Stack Pattern是否有被改變,若有就表示有Stack Overflow的汙染,進而就位觸發Abort,讓開發者有機會即早預防.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(可參考 build/core/combo/linux-arm.mk中有關GLOBAL_CFLAGS編譯參數的設定.)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 採用 safe_iop (a safe integer operation library for C)的C函式庫. 並可提供相關乘法/除法/加法與減法的安全整數操作巨集(例如:safe_mul(),safe_div(),safe_add()與 safe_sub() )</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(可參考網頁<a href="http://code.google.com/p/safe-iop/source/browse/tags/r0.3.0/README" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://code.google.com/p/safe-iop/source/browse/tags/r0.3.0/README</a>)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, 採用dlmalloc記憶體配置與管理機制.這是由Doug Lea 從1987年開始開發的dlmalloc (全名為 Doug Lea’s Malloc).所有透過dlmalloc配置的Memory Chunk都會是8bytes Aignment,並根據Memory Chunk的使用狀況(例如:是否為Free)而有額外8或16 bytes的Chunk Header Struct成本.所配置的記憶體區塊小於256bytes就會置入SmallBin結構,如果大於256bytes就會導入TreeBin的結構中.預設的dlmalloc會以256kbytes作為要透過MMAP (以4kPage為單位配置)或BRK (延伸Data Segment的記憶體配置方式,效率較高)的判斷依據.但在Android系統中,則預設改為大於64kbytes會走MMAP,小於則走BRK.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">2.3(GinberBread)之後</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="662">1, 加上format-security編譯選項,用以在使用像是printf/scanf這類會用到字串型態的函式中,可針對非字串格式的參數進行警告.在編譯參數上,設定的方式為 “-Werror=format-security”,v讓屬於 format-security 的警告,在編譯過程中會以Error的方式呈現.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 加上GCC編譯參數–noexecstack , 用以讓程式載入後Stack會透過MMU設定不可執行. (Hardware-based No eXecute (NX)),如此可避免像是透過Stack-Overflow將程式碼注入的軟體攻擊問題.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, mmap_min_addr 的設定是在Linux Kernel 2.6.23之後導入的機制,主要目的為避免非特權等級的使用者行程在非許可的低記憶體位址空間中產生記憶體映射,而發生Linux潛在的安全問題發生(像是跳到鄰近0x00000000附近的記憶體位址執行程式碼或讀取資料). 設定Kernel “vm.mmap_min_addr”後, 像是 Stack Top與MMAP的位址會被確保不低於所許可的記憶體範圍(mmap_min_addr).以最新的Jelly Bean來說,可以參考檔案”system/core/rootdir/init.rc”,其中有關於如下的設定</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>write /proc/sys/vm/mmap_min_addr 32768</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也就是說在Jelly Bean中 mmap_min_addr的值預設為32768. (預設MMAP不小於32kbytes).</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">4.0(ICS)之後</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="662">1,在ICS中就已經開啟 Address Space Layout Randomization (ASLR) 的支援,可以看到 ICS 原始碼中的檔案 ” system/core/rootdir/init.rc”, 有如下的設定<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/sys/kernel/randomize_va_space 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ASLR 參數設定為2,表示包括 MMAP, Stack, VDSO(Virtual Dynamic Shared Object)與Heap使用的BRK (To Change Data Segment Size),都會因此而進行Memory Address的Random.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">4.1 (Jelly Bean)之後</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="662">1,支援PIE (Position Independent Executable)讓應用程式能以ELF Dynamic Shared Object方式編譯後產生檔案格式 ,搭配ASLR可讓應用程式的起點不限於0x8000,可以由高位址到低位址,或是基於MMAP 0x40000000的起點開始載入應用程式.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,透過GCC編譯選項 “-Wl,-z,relro -Wl,-z,now” 支援 Read-only relocations / immediate binding ,一般來說,.plt表格屬性會是RELRO (RELocation Read-Only),在載入到記憶體後會是落在唯讀的分頁中,但.got.plt 表格卻是Read/Writeable以便支援Linker Lazy Loading,加速應用程式載入的效率. 而開啟這功能就會關閉Linker Lazy Loading機制,讓原本可讀可寫的.got.plt表格,會在載入時就先填完.got.plt 表格,並分配到唯讀的分頁中,用以避免惡意程式修改.got.plt表格改變程式的執行流程,而導致不可預期的結果.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,支援dmesg_restrict ,可避免系統訊息被未經可能的使用者讀取.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,支援kptr_restrict enabled (avoid leaking kernel addresses),可避免系統核心模組的對應Symbol記憶體位址,被未經許可的操作讀取出來,而造成可能的安全攻擊操作.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而除上述安全特徵演進外, Jelly Bean還悄悄的加入了對同裝置“多”使用者操作環境的預備,在Jelly Bean前,每個應用程式的使用者ID都會是 “app_” 開頭的命名,並不會有User ID 數字的進一步區分.但到了Jelly Bean,這樣的命名方式改為 “u0_a”開頭,也就是說預設的第一個使用者為User-ID 0,隨後再以所安裝的應用程式編號來加以區分.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而其它包括到Linux Kernel層級的安全特徵支援,筆者將在隨後章節加以介紹.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Read-only relocations / immediate binding</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於要能支援Lazy Loading機制,.got.plt (Global Offset Table & Procedure Linkage Table) Section 在應用程式載入後,還會維持可寫入的狀態,如下圖所示,程式所呼叫的printf函式,會透過.plt (Procedure Linkage Table)參考.got.plt中的_GLOBAL_OFFSET_TABLE_ 執行在應用程式啟動時,動態載入libc.so函式庫中的printf函式,透過這個Entry可以記錄當下動態載入printf函式的記憶體位址,以供後續執行. 但也因為這樣的需求存在,會讓惡意的應用程式有機會在RunTime運作過程中透過修改.got.plt表格而影響到正常應用程式的執行.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrepC6AaW4RaXOujfLlSBvFuSQ2DWIyCc71vaawnn_yoN6tyshc9RwWgbJyL10aEVsGP0wZ6yyzHpImDRtKUrhA8x1JOMjQJjst-4hyI_i3cgWq8iXNgRoy2uxO8awSYZbLn4YaVemAKo/s1600/image0011%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="829" data-original-width="1158" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrepC6AaW4RaXOujfLlSBvFuSQ2DWIyCc71vaawnn_yoN6tyshc9RwWgbJyL10aEVsGP0wZ6yyzHpImDRtKUrhA8x1JOMjQJjst-4hyI_i3cgWq8iXNgRoy2uxO8awSYZbLn4YaVemAKo/s1600/image0011%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也因此,可以在編譯的過程加上“-Wl,-z,relro -Wl,-z,now” 選項, 其中 “–Wl” 是讓其後的編譯選項可被傳入給Link,而“-z,relro” 是指讓編譯器Enable .got.plt RELRO (RELocation Read-Only),“-z now” 是指讓編譯器關閉 lazy loading.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以如下範例程式,來驗證對 .got.plt Entry的Read-Only分頁配置</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="697">int main (int argc, char *argv[])<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int *vpGOTPLT;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(argc<2)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Plz enter target .got.plt entry address!\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vpGOTPLT = (int *)strtol (argv[1], NULL, 16);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vpGOTPLT[0] = 0x12345678;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf (“.got.plt entry address: %xh\n”, vpGOTPLT);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在不打開”Read-only relocations / immediate binding “的情況下編譯,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#gcc -g -o testA test.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
讀取.got.plt中屬於printf函式Entry的位址</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#readelf -r testA|grep printf</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
08049734 00000407 R_386_JUMP_SLOT 00000000 printf</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過 gdb執行testA,並透過指令 “r” 把printf函式Entry位址0x08049734帶入給執行檔</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# gdb testA</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) r 0x08049734</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Starting program: /home/loda/test/testA 0x08049734</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Program received signal SIGSEGV, Segmentation fault.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x12345678 in ?? ()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>可以發現printf</strong><strong>函式Entry</strong><strong>被改為0x12345678,</strong><strong>也就是說.got.plt</strong><strong>被程式更改了.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來我們重新以打開”Read-only relocations / immediate binding “的情況下編譯,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#gcc -Wl,-z,relro -Wl,-z,now -g -o testB test.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
讀取.got.plt中屬於printf函式Entry的位址</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#readelf -r testB|grep printf</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
08049ff4 00000407 R_386_JUMP_SLOT 00000000 printf</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過 gdb執行testB,並透過指令 “r” 把printf函式Entry位址0x08049ff4帶入給執行檔</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# gdb testB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) r 0x08049ff4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Starting program: /home/loda/test/testB 0x08049ff4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Program received signal SIGSEGV, Segmentation fault.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0804848e in main (argc=2, argv=0xbffff744) at test.c:14</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
14 vpGOTPLT[0] = 0x12345678;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>可以發現因為.got.plt </strong><strong>為Read-Only</strong><strong>所以對printf</strong><strong>函式Entry</strong><strong>寫入的動作就被Segment Fault</strong><strong>阻擋了.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於上述驗證的結果,下圖為在ICS上沒開啟”Read-only relocations / immediate binding “的記憶體示意圖,可以看到.got.plt Section會跟Writable Content同樣被配置到可寫入的分頁中.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnMboPux0cKkL2o4CrGfvS2cdtO_otvFQho3RhhSzd4tQHZxfmUb2Wg3BNLFEVhj6vr7UkxxSX1ewXHWbL_-2z3vW-117ylBmo7yI9hCsVaAZm7tmLTS9fd4uE2ONirFhnXGbUXhCiwQI/s1600/image0031%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="683" data-original-width="643" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnMboPux0cKkL2o4CrGfvS2cdtO_otvFQho3RhhSzd4tQHZxfmUb2Wg3BNLFEVhj6vr7UkxxSX1ewXHWbL_-2z3vW-117ylBmo7yI9hCsVaAZm7tmLTS9fd4uE2ONirFhnXGbUXhCiwQI/s1600/image0031%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">但在Jelly Bean上基於”Read-only relocations / immediate binding “的開啟,可以看到.got.plt Section會被配置到Read-Only分頁中,而跟Writable Content分開.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgBTW1ldNonGpyLNrFPXuF5YJHbq1pPXTDas4TlO9D_UJ_BW7DSD95EhbN3hGb2jZYY8fnpeWZp2dOtdGa5m1CO21v3j6TMNu8YT2-GiGuPe3pWiVlYfEHRzhw5_tSwbm-0CfcYpM3L8M/s1600/image004%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="676" data-original-width="646" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgBTW1ldNonGpyLNrFPXuF5YJHbq1pPXTDas4TlO9D_UJ_BW7DSD95EhbN3hGb2jZYY8fnpeWZp2dOtdGa5m1CO21v3j6TMNu8YT2-GiGuPe3pWiVlYfEHRzhw5_tSwbm-0CfcYpM3L8M/s1600/image004%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於這部份的說明,我們可知道Jelly Bean在記憶體分頁上,有相當不錯的安全層級改善.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android 2.3 GB</strong><strong>之後支援的</strong><strong>Stack Hardware-based No eXecute (NX)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GCC 支援的noexecstack編譯屬性,可用以讓程式載入後Stack會透過MMU設定不可執行. (Hardware-based No eXecute (NX)),</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為Android 2.2 Froyo的Process Maps</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="691">………..<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afc00000-afc01000 r-xp 00000000 1f:00 356 /system/lib/libstdc++.so</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afc01000-afc02000 rwxp 00001000 1f:00 356 /system/lib/libstdc++.so</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd00000-afd3f000 r-xp 00000000 1f:00 368 /system/lib/libc.so</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd3f000-afd42000 rwxp 0003f000 1f:00 368 /system/lib/libc.so</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd42000-afd4d000 rwxp afd42000 00:00 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b0001000-b000c000 r-xp 00001000 1f:00 615 /system/bin/linker</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b000c000-b000d000 rwxp 0000c000 1f:00 615 /system/bin/linker</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b000d000-b0016000 rwxp b000d000 00:00 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>be8de000-be8f3000 </strong><strong>rwxp</strong><strong> befeb000 00:00 0 </strong><strong>[stack]</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=>Stack</strong><strong>這區塊的記憶體是設定為可執行的. “eXecute”.</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為Android 2.3 GingerBread的Process Maps</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="694">afc00000-afc01000 r-xp 00000000 1f:00 326 /system/lib/libstdc++.so<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afc01000-afc02000 rwxp 00001000 1f:00 326 /system/lib/libstdc++.so</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd00000-afd40000 r-xp 00000000 1f:00 351 /system/lib/libc.so</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd40000-afd43000 rwxp 00040000 1f:00 351 /system/lib/libc.so</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd43000-afd4e000 rwxp afd43000 00:00 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b0001000-b0009000 r-xp 00001000 1f:00 606 /system/bin/linker</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b0009000-b000a000 rwxp 00009000 1f:00 606 /system/bin/linker</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b000a000-b0013000 rwxp b000a000 00:00 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>bea0a000-bea1f000 </strong><strong>rw</strong><strong>-p befeb000 00:00 0 </strong><strong>[stack]</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=>Stack</strong><strong>這區塊的記憶體,</strong><strong>可執行 “eXecute” </strong><strong>選項被關閉了.</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由此可知,要透過Stack-Overflow打入程式碼到目標手機或程式中執行的難度就大幅提高了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GCC </strong><strong>支援的</strong><strong>stack-protector</strong><strong>機制簡述</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以ARM GCC來說,如果有加上-fstack-protector參數,當一個函式有配置8bytes或大於8bytes以上的Array時 (例如 char vpTmp[8]),就會在編譯這函式時,在這函式的進入點與離開加入Stack是否有Overflow的檢查,例如</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 886px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="886"><strong>000084c4 <FuncC>:</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>//</strong><strong>函式起點</strong><strong>.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84c4: e92d4800 push {fp, lr}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84c8: e28db004 add fp, sp, #4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……..</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84d4: e59f3060 ldr r3, [pc, #96] ; 853c <FuncC+0x78></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84d8: e5933000 ldr r3, [r3] <strong>//</strong><strong>取得</strong><strong>__stack_chk_guard</strong><strong>的數字</strong><strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84dc: e50b3008 str r3, [fp, #-8]<strong>//</strong><strong>把</strong><strong>__stack_chk_guard</strong><strong>數字寫入</strong><strong>Stack</strong><strong>中</strong><strong>.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……..</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
851c: e59f3018 ldr r3, [pc, #24] ; 853c <FuncC+0x78></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8520: e51b2008 ldr r2, [fp, #-8]<strong>//</strong><strong>從</strong><strong>Stack</strong><strong>中取回</strong><strong>__stack_chk_guard</strong><strong>數字</strong><strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8524: e5933000 ldr r3, [r3]<strong>//</strong><strong>取得原本的</strong><strong>__stack_chk_guard</strong><strong>數字</strong><strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8528: e1520003 cmp r2, r3 <strong>//</strong><strong>比對是否</strong><strong>Stack</strong><strong>有被污染</strong><strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
852c: 0a000000 beq 8534 <FuncC+0x70><strong>//</strong><strong>如果比對成功</strong><strong>,</strong><strong>就完成函式</strong><strong>FuncC</strong><strong>的執行</strong><strong>,</strong><strong>順便返回</strong><strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8530: ebffffb5 bl 840c <_init+0x50><strong>//</strong><strong>比對失敗</strong><strong>,</strong><strong>就呼叫函式</strong><strong>__stack_chk_fail,</strong><strong>進行後續錯誤處理</strong><strong>!!</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8534: e24bd004 sub sp, fp, #4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8538: e8bd8800 pop {fp, pc}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
853c: 000108e0 andeq r0, r1, r0, ror #17 <strong>//</strong><strong>儲存原本</strong><strong> __stack_chk_guard</strong><strong>值在記憶體中的位址</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>//</strong><strong>函式結尾</strong><strong>.</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如上所示,就可以知道Stack Protector的保護機制與它施行的方式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>APP User-ID </strong><strong>命名的改變</strong><strong> (for Multi-User Usage)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
相信大家最近一定也有看到這則新聞 “傳谷歌將為Android增加多用戶登錄功能” (可參考<a href="http://news.zol.com.cn/311/3113094.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://news.zol.com.cn/311/3113094.html</a>),雖然這件事情尚未成為Jelly Bean一個主要的亮點,但如果有注意到Android User-ID based Access Control機制的開發者,一定也會注意到Android Application Sandbox 中所採取的User-ID命名規則在Jelly Bean中已經改變了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
主要的差異在於過往並沒有考慮不同使用者帳號登入的問題,只會以應用程式安裝的APP ID當做APP使用者ID的定義,但到了Jelly Bean中這些APP User –ID命名方式有了全然的改變.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先參考ICS上應用程式安裝後,每個應用程式所對應的使用者帳號命名如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="635"><strong>app_6 146 37 158720 34664 ffffffff 400113c0 S com.android.inputmethod.latin</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>radio 162 37 177336 35884 ffffffff 400113c0 S com.android.phone</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_13 176 37 177672 55180 ffffffff 400113c0 S com.android.launcher</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>system 197 37 167584 40008 ffffffff 400113c0 S com.android.settings</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_1 218 37 177756 48400 ffffffff 400113c0 S android.process.acore</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_21 241 37 162396 32096 ffffffff 400113c0 S com.android.calendar</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_34 275 37 159648 31712 ffffffff 400113c0 S com.android.deskclock</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_1 291 37 164348 34864 ffffffff 400113c0 S com.android.contacts</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_11 304 37 160416 32108 ffffffff 400113c0 S com.android.providers.calendar</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_7 333 37 160556 32752 ffffffff 400113c0 S android.process.media</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_17 349 37 161956 31188 ffffffff 400113c0 S com.android.exchange</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_27 363 37 170720 35940 ffffffff 400113c0 S com.android.email</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_28 384 37 159412 32068 ffffffff 400113c0 S com.android.mms</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_2 439 37 165780 34304 ffffffff 400113c0 S com.android.browser</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>app_14 460 37 156692 29776 ffffffff 400113c0 S com.android.sharedstoragebackup</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以看到每個應用程式都會對應到一個 “app_” 開頭的應用程式User-ID命名,而同樣的情況到了Jelly Bean時則變成如下的情況</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="646"><strong>u0_a28 206 37 184872 50852 ffffffff 40033a40 S com.android.systemui</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>u0_a3 220 37 173036 35052 ffffffff 40033a40 S com.android.inputmethod.latin</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>radio 233 37 181864 35064 ffffffff 40719100 R com.android.phone</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>u0_a15 248 37 172876 34932 ffffffff 40032b64 S com.android.launcher</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>system 271 37 180932 38708 ffffffff 40033a40 S com.android.settings</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>u0_a13 297 37 176084 33016 ffffffff 40033c74 S android.process.acore</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>u0_a13 330 37 177340 33016 ffffffff 40033a40 S com.android.contacts</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>u0_a0 353 37 165644 25096 ffffffff 4075cda2 R com.android.providers.calendar</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會嘗試區分不同User-ID 所安裝的第幾個APP ID,而這樣的設計概念就可符合未來有可能支援的多使用者同裝置的使用行為.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>防止</strong><strong> Kernel Message</strong><strong>洩漏</strong><strong> (dmesg)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel DMESG 是我們在除錯Kernel核心或是模組時,一個非常好用的功能與機制,但在Linux Kernel 2.6.37 之後有支援新的Linux Kernel作業系統核心設定選項 “CONFIG_DMESG_RESTRICT” 可開啟用以限定是否一般使用者無法透過像dmesg指令去讀取Linux Kernel核心所吐出的訊息,而導致潛在的作業系統安全資訊外露.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以透過設定</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
echo “0” > /proc/sys/kernel/dmesg_restrict</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以解除dmesg取得Linux Kernel核心訊息的限制,讓開發者可讀取即時的作業系統核心訊息.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
echo “1” > /proc/sys/kernel/dmesg_restrict</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可用以關閉透過dmesg取得Linux Kernel核心訊息的路徑</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以參考Jelly Bean 原始碼內的檔案 ”system/core/rootdir/init.rc” 有如下設定</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>write</strong><strong> /proc/sys/kernel/dmesg_restrict 1</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可知Jelly Bean中對DMESG的保護是預設打開的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>禁止</strong><strong> Kernel Symbol </strong><strong>位址洩漏</strong><strong> (kptr)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
原本我們可以透過 “/proc/kallsyms”去查詢Linux Kernel Symbol所對應的記憶體位址,不論是出於除錯的或解決問題的目的,或是站在破解系統的角度,希望可以洞悉作業系統內部的祕密或有關的系統核心函式記憶體位址,讓有其他意圖的系統開發者可以有施力點,此時就會透過這些核心的記憶體位址來做為參考與評估依據.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但是在新版的Jelly Bean中,搭配新版的Linux Kernel就可以透過Proc檔案系統註冊的Device Node “/proc/sys/kernel/kptr_restrict” 來設定對於這機制的開啟與否,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果要關閉這機制就可以透過</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Echo “0” > /proc/sys/kernel/kptr_restrict</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果要開啟就可以透過</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Echo “1” > /proc/sys/kernel/kptr_restrict</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以參考Jelly Bean 原始碼內的檔案 ”system/core/rootdir/init.rc” 有如下設定</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>write</strong><strong> /proc/sys/kernel/kptr_restrict 2</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可知Jelly Bean中對Kernel Symbol的保護是預設打開的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>PIE (Position independent executable)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於GCC的PIE編譯選項,可讓應用程式執行時不用被限制在固定的記憶體起點,可以根據搭配的亂數記憶體起點機制,讓不同的Process行程有不同的載入執行位址,大幅度提高系統的安全性.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先,可以透過像是arm-eabi-readelf 或是去CoreSourcery下載的arm-none-linux-gnueabi- readelf來對Android Jelly Bean PIE檔案進行比對,以便瞭解在ICS與Jelly Bean上兩邊檔案格式的差異.如下所示為我們透過Read-ELF工具比對後的結果,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 730px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="198"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="260"><strong>Android 4.0.3</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="272"><strong>Android 4.1.1</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="198"><strong>/init</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="260"><strong>Type: EXEC (Executable file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x80c0</strong></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="272"><strong>Type: EXEC (Executable file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x80e0</strong></div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="198"><strong>/system/bin/app_process</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="260"><strong>Type: EXEC (Executable file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x8bd0</strong></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="272"><strong>Type: DYN (Shared object file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0xb20</strong></div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="198"><strong>/system/bin/linker</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="260"><strong>Type: EXEC (Executable file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0xb0001000</strong></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="272"><strong>Type: DYN (Shared object file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x36e0</strong></div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="198"><strong>/system/bin/ rild</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="260"><strong>Type: EXEC (Executable file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x8ab0</strong></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="272"><strong>Type: DYN (Shared object file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0xa20</strong></div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="198"><strong>/system/xbin/showmap</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="260"><strong>Type: EXEC (Executable file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x8860</strong></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="272"><strong>Type: DYN (Shared object file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x7a0</strong></div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="198"><strong>/system/lib/libc.so</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="260"><strong>Type: DYN (Shared object file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x0</strong></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="272"><strong>Type: DYN (Shared object file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x0</strong></div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="198"><strong>/system/lib/libdvm.so</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="260"><strong>Type: DYN (Shared object file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x0</strong></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="272"><strong>Type: DYN (Shared object file)</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Entry point address: 0x0</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以看到相對於Android 4.0 ICS,在Android 4.1 Jelly Bean上多數的應用程式都已經變成DYN (Shared Object File)檔案格式,也就是說這些ELF執行檔是可以被隨機載入到不同的記憶體位址中執行,而不像是Android 4.0 ICS上的執行檔,必須以0x8000分頁為起點被載入執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以ARM Linux來說,一般的ELF可執行檔載入記憶體的起點會是在0x8000,參考上表可以看到包括Android應用的原生碼載入程式app_process,或RIL Daemon或像是ShowMap這類原生工具程式,載入點都會是以0x8000為基礎去計算.但在Jelly Bean的環境下,除了少數像 init 啟動程式還維持0x8000為基礎的載入外,像是Java應用,或其他原生應用工具程式都會以 PIE 參數進行編譯,並產生Dynamic Loading的格式,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,為一般Arm Linux上Linux Kernel/Modules 與 應用程式的記憶體Mapping,</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRTJcR88Vj3JvGW_DzLmd4aztf8FsADuqrJrMtHaZ5zzPzEaWCQkK2GM4FGUv2fg-ZQqtV3qZueoNqyMUq0QNRSmO5Es-waecbC2kT0JIhDpZjF-HYPrvcyaucB01QAP-vBeXDoQQST3U/s1600/image006%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="536" data-original-width="533" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRTJcR88Vj3JvGW_DzLmd4aztf8FsADuqrJrMtHaZ5zzPzEaWCQkK2GM4FGUv2fg-ZQqtV3qZueoNqyMUq0QNRSmO5Es-waecbC2kT0JIhDpZjF-HYPrvcyaucB01QAP-vBeXDoQQST3U/s1600/image006%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">如下圖所示,則為基於PIE (Position independent executable)技術下,ARM ELF應用程式執行檔就可以根據需求跳脫0x8000執行檔載入記憶體的限制,</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMTnyShmu3FnDw3P1oksZ_gzNWyfnum6YdBpnfKSyoTp6ED6hdOrYUB_PcgQFdStNY4l6LCZRAvpEXT6rCHaS6D4EzF6Fo8bvqGQUuw-h3A07Fh4PkKcgc5HwOY07ol7Krf18O4NxHDq8/s1600/image008%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="534" data-original-width="691" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMTnyShmu3FnDw3P1oksZ_gzNWyfnum6YdBpnfKSyoTp6ED6hdOrYUB_PcgQFdStNY4l6LCZRAvpEXT6rCHaS6D4EzF6Fo8bvqGQUuw-h3A07Fh4PkKcgc5HwOY07ol7Krf18O4NxHDq8/s1600/image008%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PIE機制是可以透過編譯選項關閉的. 在Disable PIE機制後,應用程式的起點就會重新回到0x8000,但也就因此少了基於PIE所增加的系統安全性優點了. 至於如何取捨,還是以開發者實際的需求為主.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>ASLR (Address space layout randomization)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其實在ICS中,init.rc中就已經有如下的設定</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>write</strong><strong> /proc/sys/kernel/randomize_va_space 2</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也就是說早在ICS時,就已經有預備要對User-Space應用程式的MMAP, Stack, VDSO(Virtual Dynamic Shared Object)與Heap使用的BRK (Extend Data Segment)進行Memory Address Random的預備. 但直到了Jelly Bean,搭配改善後的Linker機制,才讓ASLR正式的在Android上完整的發揮實力.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
提到ASLR通常最直接的兩個問題就是,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,</strong><strong>程式Fork</strong><strong>出去後,</strong><strong>新產生的Task</strong><strong>由於他的父行程已經把相關的Symbol Run-Time Link</strong><strong>好了,</strong><strong>是否也會因此而被影響到呢?</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>答案是不會的,ASLR主要是在行程初始化時進行Random位址的選擇,所有從這父行程Fork出去的子行程,或是透過pthread產生的執行緒都會延續父行程的記憶體Mapping結果. (這也是讓問題最簡單處理的方式)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,</strong><strong>記憶體位址Random</strong><strong>機制,</strong><strong>是否會在每次記憶體Mmap</strong><strong>時都做一次呢?</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>答案是不會的,只會在行程初始時Random一次MMAP起點與Stack位址,之後就不會再去反覆的Random.原因在於,就算沒有ASLR其實每次去觀察應用程式動態函式庫或是MMAP得到的位址,我們都會發現就算是同樣的操作行為,因為每次執行時多工環境下的種種因素,這些動態環境的差異就會導致這些記憶體位址的改變了,也因此只要在啟動時有一個Random,再加上後續的時間與動態環境變動,就會讓ASLR有非常棒的效果. (足以讓想要鎖定特定記憶體位址呼叫特定函式攻擊的手法無力可施).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前的ASLR共有兩種記憶體Random Mapping的方式,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, 由高位址往低位址開始Random</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 由0x40000000 的起點1MB範圍內 開始往上 Random (缺點是會導致應用程式可用記憶體變少,所以……實際應用上是需要調整一下的..)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Jelly Bean 預設為路徑 1, 運作概念可參考下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRS83_NnF5zTL9HV3Th7VlHIzFsl8THGRNvz-81AXUpmvyYHQr4U7iPOoAOkP2SvfqK0OwtOVK0UH-JjN88qrOX1s6z5-BVDQ9lPqBJEviODBbTQN3tUiTwJHP0gBQcApnjO2zZVirjag/s1600/image010%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="561" data-original-width="691" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRS83_NnF5zTL9HV3Th7VlHIzFsl8THGRNvz-81AXUpmvyYHQr4U7iPOoAOkP2SvfqK0OwtOVK0UH-JjN88qrOX1s6z5-BVDQ9lPqBJEviODBbTQN3tUiTwJHP0gBQcApnjO2zZVirjag/s1600/image010%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">如下圖所示,為由0x40000000 開始做Random Mapping的運作概念示意圖,而Random的範圍為0x40000000-0x40100000.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSszUoIiJCQuoLG8GTEvdIL7T0z-aMS6OGOs_PCZA0Hqg7rTrcF2NszpLc0LaXRS6wINjNbzL3IiQu2iCLxvpdvvGVlLCiAtuMR1JZEpR200ZlW1zl2HpwVbMS3mlwF4BmIBwXXpXx8Cs/s1600/image012%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="565" data-original-width="692" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSszUoIiJCQuoLG8GTEvdIL7T0z-aMS6OGOs_PCZA0Hqg7rTrcF2NszpLc0LaXRS6wINjNbzL3IiQu2iCLxvpdvvGVlLCiAtuMR1JZEpR200ZlW1zl2HpwVbMS3mlwF4BmIBwXXpXx8Cs/s1600/image012%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來不免俗的,還是要稍微帶一下程式碼,首先我們參考函式arch_pick_mmap_layout (source code in arch/arm/mm/mmap.c),可看到如下的程式碼,當目前Process的Flags有被標記為Randomize,且Process的Personality沒有Disable Randomize選項. 會先透過get_random_int取得一個32-bits整數,然後除256 (也就是1<<8)取餘數,如此會得到一個介於0-255的隨機數字. 搭配12-bits的PAGE_SHIFT,就可以得到一個介於1MB範圍內的記憶體Random範圍.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="618"><pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;">258 <strong>void</strong> <a href="http://hala01.com/src/android-kernel/android-3.4/HTML/R/421542.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple referred from 3 places.">arch_pick_mmap_layout</a>(<strong>struct</strong> <a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/2665.html#L288" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 288 in include/linux/mm_types.h.">mm_struct</a> *<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/220555.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 7458 places.">mm</a>)</pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;">259 <em>{</em></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"> 260 <strong>unsigned</strong> <strong>long</strong> <a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282797.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 17 places.">random_factor</a> = 0UL;</pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"> 261</pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"> 262 <em>/* 8 bits of randomness in 20 address space bits */</em></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"> 263 <strong>if</strong> ((<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/777736.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 19 places.">current</a>-><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/822062.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 14 places.">flags</a> & <a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/3633.html#L1828" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1828 in include/linux/sched.h.">PF_RANDOMIZE</a>) &&</pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"> 264 !(<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/777736.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 19 places.">current</a>-><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/3828.html#L110" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 110 in include/linux/personality.h.">personality</a> & <a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/3828.html#L26" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 26 in include/linux/personality.h.">ADDR_NO_RANDOMIZE</a>))</pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"> 265 <a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282797.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 17 places.">random_factor</a> = (<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/38455.html#L1348" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1348 in drivers/char/random.c.">get_random_int</a></pre>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
() % (<strong>1 << 8</strong>)) << <strong><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/401313.html" style="color: #666666; text-decoration-line: none;" title="Multiple defined in 53 places.">PAGE_SHIFT</a>;</strong></div>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"> 266</pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"> 267 <strong>if</strong> (<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/900708.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 5 places.">mmap_is_legacy</a></pre>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
()) <em>{</em></div>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/900708.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 5 places."> 268 <span style="text-decoration-line: underline;">mm</span>-><span style="text-decoration-line: underline;">mmap_base</span> = <span style="text-decoration-line: underline;">TASK_UNMAPPED_BASE</span> + <span style="text-decoration-line: underline;">random_factor</span>;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282797.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 17 places."> 269 <span style="text-decoration-line: underline;">mm</span>-><span style="text-decoration-line: underline;">get_unmapped_area</span> = <span style="text-decoration-line: underline;">arch_get_unmapped_area</span>;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/724118.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 13 places."> 270 <span style="text-decoration-line: underline;">mm</span>-><span style="text-decoration-line: underline;">unmap_area</span> = <span style="text-decoration-line: underline;">arch_unmap_area</span>;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/724289.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 2 places."> 271 <em>}</em> <strong>else</strong> <em>{</em></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/724289.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 2 places."> 272 <span style="text-decoration-line: underline;">mm</span>-><span style="text-decoration-line: underline;">mmap_base</span> = <span style="text-decoration-line: underline;">mmap_base</span>(<span style="text-decoration-line: underline;">random_factor</span>);</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282797.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 17 places."> 273 <span style="text-decoration-line: underline;">mm</span>-><span style="text-decoration-line: underline;">get_unmapped_area</span> = <span style="text-decoration-line: underline;">arch_get_unmapped_area_topdown</span>;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/724121.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 7 places."> 274 <span style="text-decoration-line: underline;">mm</span>-><span style="text-decoration-line: underline;">unmap_area</span> = <span style="text-decoration-line: underline;">arch_unmap_area_topdown</span>;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c."> 275 <em>}</em></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 612.213px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c."> 276 <em>}</em> </a></pre>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c."></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c."></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c.">同樣的,另一個也會一起Random的就是Stack,可以參考如下randomize_stack_top (Source Code in fs/binfmt_elf.c)程式碼,其中STACK_RND_MASK在檔案”fs/binfmt_elf.c”中的宣告如下所示</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c."></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c.">#define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT – 12)) /* 8MB of VA */</a></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c.">(由此可知,Stack Top隨機Random範圍是8MB.)</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c."></a></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="613"><pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/7916.html#L1569" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1569 in mm/mmap.c.">
540 <strong>static</strong> <strong>unsigned</strong> <strong>long</strong> <span style="text-decoration-line: underline;">randomize_stack_top</span>(<strong>unsigned</strong> <strong>long</strong> <span style="text-decoration-line: underline;">stack_top</span>)</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/36892.html#L126" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 126 in drivers/media/media-entity.c.">541 <em>{</em></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/36892.html#L126" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 126 in drivers/media/media-entity.c."> 542 <strong>unsigned</strong> <strong>int</strong> <span style="text-decoration-line: underline;">random_variable</span> = 0;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."> 543 </a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."> 544 <strong>if</strong> ((<span style="text-decoration-line: underline;">current</span>-><span style="text-decoration-line: underline;">flags</span> & <span style="text-decoration-line: underline;">PF_RANDOMIZE</span>) &&</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/3633.html#L1828" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 1828 in include/linux/sched.h."> 545 !(<span style="text-decoration-line: underline;">current</span>-><span style="text-decoration-line: underline;">personality</span> & <span style="text-decoration-line: underline;">ADDR_NO_RANDOMIZE</span>)) <em>{</em></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/S/3828.html#L26" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Defined at 26 in include/linux/personality.h."> 546 <span style="text-decoration-line: underline;">random_variable</span> = <strong><span style="text-decoration-line: underline;">get_random_int</span></strong><strong>() & </strong><strong><span style="text-decoration-line: underline;">STACK_RND_MASK</span></strong><strong>;</strong></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/544826.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 5 places."> 547 <span style="text-decoration-line: underline;">random_variable</span> <strong><<= </strong><strong><span style="text-decoration-line: underline;">PAGE_SHIFT</span></strong>;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/401313.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 53 places."> 548 <em>}</em></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/D/401313.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple defined in 53 places."> 549 <em>#ifdef</em> <span style="text-decoration-line: underline;">CONFIG_STACK_GROWSUP</span></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/9339.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 12 places."> 550 <strong>return</strong> <span style="text-decoration-line: underline;">PAGE_ALIGN</span>(<span style="text-decoration-line: underline;">stack_top</span>) + <span style="text-decoration-line: underline;">random_variable</span>;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."> 551 <em>#else</em></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."> 552 <strong>return</strong> <span style="text-decoration-line: underline;">PAGE_ALIGN</span>(<span style="text-decoration-line: underline;">stack_top</span>) - <span style="text-decoration-line: underline;">random_variable</span>;</a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."> 553 <em>#endif</em></a></pre>
<pre style="font-family: "Courier New", Courier, monospace; font-size: 1em; overflow-x: auto; overflow-y: hidden; padding-bottom: 1.5em; width: 607.463px; word-wrap: normal;"><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."> 554 <em>}</em></a></pre>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places.">如果想要關閉ASLR的核心運作機制,可以透過</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places.">echo “0” > /proc/sys/kernel/randomize_va_space</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places.">來進行關閉.</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; text-decoration-line: none;" title="Multiple used in 5 places.">結語</a></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places.">本文簡要的說明最新Android Jelly Bean安全機制的演進,而這些安全機制其實也隱含了對於作業系統額外的執行成本.舉例來說,以Kernel Memory Management Code Path路徑來看,當記憶體要改為Top-Down的計算方式,所要執行配置記憶體路徑也會稍微變長,增加系統的執行成本.</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places.">但如果是站在系統安全的角度去看問題,越能以出於一般人Down-Top思維的概念去設計一個防堵安全機制的作業系統,其實就越讓這個作業系統的安全組態配置立於不敗之地.畢竟,想要破解它的人思維就必須要透過傳統Down-Top思維,改用以Top-Down + Random的角度去看問題.</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places."></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places.">從古至今,絕對沒有一個作業系統是可以聲稱100%安全的,原因在於人的思想與創造力總是遠超過當下看文章或寫文章的你我.但也因為如此,Linux Kernel作業系統才會不斷的演進,用更多新的機制去補強這些核心的機制,讓安全問題可以在每一版的作業系統核心中,取得當時最適當的解決.</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://hala01.com/src/android-kernel/android-3.4/HTML/Y/282811.html" style="color: #666666; font-weight: bold; text-decoration-line: none;" title="Multiple used in 5 places.">本文到此結束,希望對各位有所幫助,加油!!!!</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-36237607217292767762017-06-04T09:55:00.003-07:002017-06-04T09:55:40.990-07:00HITCON 2012 – Hacks in Taiwan Conference 台灣駭客年會投影片<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
HITCON 2012 – Hacks in Taiwan Conference 台灣駭客年會投影片</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
感謝HITCON朋友們的協助, 這次的聚會對自己收穫也很大,<br />尤其傍晚在台啤餐廳的Party真的很棒.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Session結束時,有人提到投影片的更新問題,<br />我把最新版本放在這.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="https://drive.google.com/open?id=0B5pbq4t2T2_fM2h1dnd3TFRud0E">Introduce LLVM from a hacker’s view.</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
歡迎自行取用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
loda.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMycLmluwhHj5QXZHKFiVQ-NphThdSIqvBbb_Q9NwVwICYMlblVoBQFV_yk1R5IM2vCmw7oWuZ-DGflpwtbSTHSZHeqlWpXWTK_SYMaGvwTfj9MHhO_DXVRfVZf-RU-EXPZvX7bBeZoDo/s1600/Untitled-16%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="632" data-original-width="1176" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMycLmluwhHj5QXZHKFiVQ-NphThdSIqvBbb_Q9NwVwICYMlblVoBQFV_yk1R5IM2vCmw7oWuZ-DGflpwtbSTHSZHeqlWpXWTK_SYMaGvwTfj9MHhO_DXVRfVZf-RU-EXPZvX7bBeZoDo/s320/Untitled-16%255B1%255D.png" width="320" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-19804858886258429402017-06-04T09:53:00.003-07:002017-06-04T09:53:52.706-07:00從LLVM談 Portable Native Client Software Fault Isolation技術<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
從LLVM談 Portable Native Client Software Fault Isolation技術</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>從</strong><strong>LLVM</strong><strong>談</strong><strong> Portable Native Client Software Fault Isolation</strong><strong>技術</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
by loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<a href="mailto:hlchou@mail2000.com.tw" style="color: #666666; font-weight: bold; text-decoration-line: none;">hlchou@mail2000.com.tw</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有次在閱讀文章時,看到這段話 「不,知識是有限的,只有愚蠢才是無限的。」by 叔本華(十九世紀 德國哲學家),當下會心一笑,也覺得若我們認為自己無所不知,那可能就正好落入愚蠢的陷阱了…:^o^</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會對SFI技術有興趣的主因在於,過去所認為的安全機制確保,不外乎就是透過User/Kernel Mode基於處理器的機制,把UnTrust Code的部分區隔出來,或像是透過Virtualization技術,以虛擬機環境實現同樣的目的.然而在接觸到LLVM與Google的Native Client技術後,才發現其實這條路上還有很多種可能,如果不是參考到這些作法,自己並不知道原來還可以有這樣的方案誕生. 也因此希望可以把這技術推廣給更多人知道,若能對各位有些許幫助,該當是最棒的事情了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Google在瀏覽器上推廣Native Client技術,希望藉此讓Browser應用可以達到Native應用程式的效能.而Native Client之所以可以達到這樣的目標,正是因為他可以讓Browser執行Native Code,但若僅僅如此,那層出不窮的安全問題,將成為這方案最大的罩門.也因此,SFI技術成為Google在瀏覽器上運行Native Code的安全防護機制,透過Inner/Outer Sandbox機制,讓在瀏覽器中運行的Native應用程式雖然可以直接以處理器指令運行程式,但卻被限制在Google Sandbox所預設的行為範疇中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
既然SFI解決了Native Client亟需的安全問題,另一個能讓Native Client普及的利器就是LLVM,沒有LLVM之前的Native Client只能在x86 32/64bits環境下執行,對於目前以ARM為主的手持裝置來說,無疑就有推廣上的困難,也因此Google將LLVM的跨平台特性與Native Client進行結合,發展了名為Portable Native Client的新技術,讓基於LLVM所開發的BitCode可以透過瀏覽器下載到不同的平台上,再藉由PNaCl Translate技術,把BitCode根據不同平台的差異轉為適應於該平台的Native Code,並藉由原本的Native Client SFI 技術,確保既有跨平台的特性,又兼顧潛在的安全問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前的Portable Native Client 可支援 ARM ,x86 32/64bits平台,藉此可橫跨一般的電腦與智慧型手機的應用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考下圖所示,除了Native Client會以Portable Native Client的技術來將LLVM應用到Browser的世界外,在Android手機上,包括原生的C/C++ Native應用程式,Dalvik Java ByteCode或是Render Script都可以基於LLVM技術,以BitCode的形式編譯後,在根據不同目標平台的差異,以便Translate成為目標平台最佳化後的指令集,也就是說當Android與Browser Native Client逐步普及,可預見的未來LLVM技術將會成為影響我們網際網路與手持設備應用的重要核心技術.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQiAIq-c6gurHGkkP7poe0UALPZAw5qeS3B3HwkuTdYWFEJ0QySxdNK70oWryPNaZoNM734TzHjQ39ovAN_2Sv4gcDNtzPFV-Zq1G2v4tq4FSR9cQHREdn0r1FHJ48hH1eL6bma4I9JUE/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m255c099a%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="259" data-original-width="668" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQiAIq-c6gurHGkkP7poe0UALPZAw5qeS3B3HwkuTdYWFEJ0QySxdNK70oWryPNaZoNM734TzHjQ39ovAN_2Sv4gcDNtzPFV-Zq1G2v4tq4FSR9cQHREdn0r1FHJ48hH1eL6bma4I9JUE/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m255c099a%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Portable NaCl SFI 技術,以下兩篇Paper是Google所發佈的論文,也非常有參考的價值,有興趣的開發者,可自行參閱</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,</strong>Native Client: A Sandbox for Portable, Untrusted x86 Native Code (In the 2009 IEEE Symposium on Security and Privacy,http://research.google.com/pubs/pub34913.html)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,</strong>Adapting Software Fault Isolation to Contemporary CPU Architectures (Publication Year 2010,<a href="http://research.google.com/pubs/pub35649.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://research.google.com/pubs/pub35649.html</a>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前有關 3rd-party Native Code安全執行的設計方案,主要有</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,</strong><strong>Fault-Isolation:</strong><strong> </strong>這是本文Native Client SFI所基於的概念,但基於平台的差異,還可以有所調整,例如x86 CISC指令集,可以透過Code/Data Segment Register去限制應用程式可以存取或執行的記憶體範圍,而這樣基於CISC架構的實作就稱為CFI(CISC Fault Isolation),但這樣的機制由於也利用到了x86處理器的Segment Register特性,也因此如果要應用到RISC平台,像是ARM方案時,就會有所局限性 (ARM並沒有 Segment Register).反之目前Google所採用的SFI則可無需被特定平台限制住.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,Trust with Authentication:</strong><strong> </strong>這是微軟ActiveX的作法,主要缺點為所信賴的基礎為憑證,若是沒有憑證則會跳出警告,由使用者決定安裝與否.但實際上使用者並沒有能力決定哪個軟體或應用是安全無虞的,且過多的警告訊息,也讓使用者對於Native Code傳遞到使用者端的行為,有預先認定不安全的認知.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3,System Request Moderation (User-ID based Access Control):</strong><strong> </strong>Android Application Sandbox應該就是這類實作的最佳案例.以往,在Linux執行環境,會以同一個使用者ID去執行多個應用程式,也因此每個應用程式都是基於同一個使用者ID與權限的保護下,如此的缺點就是當其中有第三方的應用程式會去進行對其它應用程式的不合法行為時,就需另外去設想其它的保護措施. Android Application Sandbox 會讓每個使用者安裝的應用程式有各自的User-ID(也就像是個Linux Kernel-Level Application Sandbox),藉此就可基於Linux Kernel每個User-ID與預設相關系統行為的特權User-ID區分,以達到應用程式的安全保護機制. 屬於第三方應用程式的User-ID,會因此無法去執行需要具備特權等級才能執行的動作或呼叫的System Call.而且由於每個應用程式會在自己所屬的User-ID權限下執行,也可以避免惡意程式對其它應用(User-ID)的不合法修改.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文重點會放在Native Client的SFI技術,並會把有關的議題逐一說明,希望對有興趣的開發者而言,可以帶來幫助.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android Portable NaCl </strong><strong>支援檔案類型</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Google的文件 ‘<a href="http://www.chromium.org/nativeclient/pnacl/pnacl-shared-libraries-final-picture" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.chromium.org/nativeclient/pnacl/pnacl-shared-libraries-final-picture</a> ‘, 在Portable NaCl執行環境中,目前支援的檔案類型如下表所示,其中包括跨平台的動態函式庫(Portable SO)與跨平台的執行檔(Portable EXE)..etc</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="221">副檔名</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="584">說明</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="221">Bitcode (.bc)</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="584">這是原本透過LLVM clang所編譯出來的 BitCode檔案格式,包含執行所需的程式與資料,但沒有PNaCl所需的MetaData.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如以 clang 編譯所產生的BitCode檔案</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
clang -O3 -emit-llvm sample.c -c -o sample.bc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可透過指令 llvm-dis 如下所示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
llvm-dis sample.bc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
把sample.bc反組譯為 sample.ll</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並可透過LLI直譯器執行或經由LLC轉譯為目標平台的Assembly</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="221">Portable Executable (.pexe)</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="584">這是透過過PNaCl clang 所編譯出來BitCode的Portable Executable檔案格式,並可再根據需求轉譯為目標平台的可執行檔 (.nexe). PEXE檔案格式跟原本的BitCode相比主要多了以下的MetaData內容,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,用以表明執行檔是靜態連結(加上-static參數編譯)還是有動態載入函式庫需求.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,會包含這檔案執行時所相依的動態函式庫.SO檔案列表</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,包含Run-Time所需來自外部的Dynamic Symbol Table,會在此記錄Symbol名稱,版本資訊與會透過哪個動態函式庫提供該Symbol</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於PNaCl Clang編譯後,就會把上述的MataData資料置入產生的PEXE檔案中.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如以 pnacl-clang 編譯所產生BitCode的PEXE檔案格式</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl-clang hello.c -o hello.pexe</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其實,對一個要下載到瀏覽器執行的NaCl檔案而言,MetaData可以透過網頁下載對應的*.NMF 檔案進行判讀.並可透過指令pnacl-nmf把PEXE檔案中的MetaData讀出,如下所示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl-nmf hello.pexe</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="221">Portable Shared Object (.pso)</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="584">這是透過過PNaCl clang 所編譯出來BitCode的Portable Shared Object檔案格式,可再轉譯為.SO動態函式庫檔案格式. 在這個.SO中還會包括以下PNaCl所需的MetaData內容<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, .So檔案與其它.SO檔案的相依性 (例如呼叫其它.SO所提供的函式)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 包含Run-Time所需來自外部的Dynamic Symbol Table</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
操作方式為在編譯過程中在pnacl-clang 工具後加入 -shared 參數.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="221">.pso</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="584">為Portable BitCode Object File,亦可透過pnacl-translate轉成Native的Object File</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="221">.nexe</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="584">為編譯為Native Code的Native Client 執行檔案格式</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="221">.so</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="584">為ELF Native Shared Library檔案格式</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於上述 BitCode,PSO,PEXE,NEXE,SO的運作概念,可彙整如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjevWQCxKfs6LsB9TLzhqhDuWHKDRdUAVKgjXLroCHSVYbA702JYDuuhn6GbgTFMTuPZsgVbdzM_1rIpdX4feKzS9G1kYpdAUMMCFuk3NnOXlCJtdkFenUvzqffOdRUDxk70tIyfMGMX8/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m5f2aff1c1%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="633" data-original-width="675" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjevWQCxKfs6LsB9TLzhqhDuWHKDRdUAVKgjXLroCHSVYbA702JYDuuhn6GbgTFMTuPZsgVbdzM_1rIpdX4feKzS9G1kYpdAUMMCFuk3NnOXlCJtdkFenUvzqffOdRUDxk70tIyfMGMX8/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m5f2aff1c1%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Chrome瀏覽器是目前驗證Native Client的最佳環境,以下將說明如何設定以支援Native Client應用程式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>讓</strong><strong>Chrome</strong><strong>瀏覽器支援</strong><strong> NaCl </strong><strong>應用下載</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考連結<a href="https://developers.google.com/native-client/devguide/devcycle/running" style="color: #666666; font-weight: bold; text-decoration-line: none;">https://developers.google.com/native-client/devguide/devcycle/running</a> 中的說明,以筆者使用的Google Chrome 19.0.1084.56版本來說,可以在瀏覽器中輸入 “about:flags” 字串,就可以看到基於 “chrome://flags/” 的chrome實驗性功能設定選項.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGsmH3mhD-u5wTOUfHHTz_f9mIvfofF0yTYLw0D3zHQqThLSKHTwKMkGzydEIz70cOCqNgxozrqPJYDa6CRtUZx4h76Sv4METKmN8nAKJ5D-XK8kUGtnIe-GLdnHP8nvwGPZnZCWuKtJw/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m4a03375a%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="407" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGsmH3mhD-u5wTOUfHHTz_f9mIvfofF0yTYLw0D3zHQqThLSKHTwKMkGzydEIz70cOCqNgxozrqPJYDa6CRtUZx4h76Sv4METKmN8nAKJ5D-XK8kUGtnIe-GLdnHP8nvwGPZnZCWuKtJw/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m4a03375a%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再試著連到支援Native Client的網頁,由於Chrome Web Store上已經有支援Native Client的Web應用程式,因此驗證最簡單的方式就是直接連到 CWS網頁上搜尋Native Client,或直接點選這個連結 <a href="https://chrome.google.com/webstore/search/native%20client" style="color: #666666; font-weight: bold; text-decoration-line: none;">https://chrome.google.com/webstore/search/native%20client</a> ,就可以找到能在Chrome瀏覽器執行的Native Client網頁應用了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CFI (CISC Fault Isolation) </strong><strong>技術介紹</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
談到CISC Fault Isolation,很直覺會想到同樣基於硬體的保護,最經典的實例應該就是一般作業系統上的User/Kernel Space,讓 UnTrust Code放在User Space,而Trust的Code放到Kernel Space,基於MMU (Memory Management Unit)的保護,User Space如果去存取Kernel Space資料內容就會發生Exception. 而User Space要執行/存取Kernel Space 程式碼/資料時,就會透過System Call,一般來說在x86是透過中斷(Windows為0x2E 與 Linux為 0x80),而在ARM平台上是透過SWI(Software Interrupt).(不只MMU機制,若有其他的硬體保護,也可算是Hardware Fault Isolation.),如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfShnyQxJcc6uJbKo85ktt5swgDCSQVDXUF-85sD19NpI2dZdnm9U6y8mB_ku6aoV1LjmcgN1rUIhSw_sfPmYjYVwzZy6TU1Ah-GoSjNVvwHNbSOcn-_iP5guPIcGz9VckY_tqCcWpDvU/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m307267b1%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="424" data-original-width="800" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfShnyQxJcc6uJbKo85ktt5swgDCSQVDXUF-85sD19NpI2dZdnm9U6y8mB_ku6aoV1LjmcgN1rUIhSw_sfPmYjYVwzZy6TU1Ah-GoSjNVvwHNbSOcn-_iP5guPIcGz9VckY_tqCcWpDvU/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m307267b1%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而跨Process間的呼叫,則可透過Socket搭配RPC (Remote Procedure Call),但因為呼叫端與被呼叫端是在兩個不同的Memory Space,由A呼叫B時,還必須要觸發行程的排程,除了Socket/RPC本身成本外,還需要加上被呼叫端B被處理器排程到,與之後回到呼叫端A處理被呼叫端B返回結果的時間成本,也因此相對於同一個Memory Space函式的彼此呼叫,RPC可算是效率相對差的方案.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而CFI技術則是在同一個Memory Space下,實現Trust/UnTrust兩個模組間的呼叫.比較CFI與SFI技術的效率差異上,根據Google文件的說明,在開啟NaCl SFI技術對程式碼Control-Flow Memory Integrity的稽核機制下,在 Cortex A9 out-of-order ARM平台上NaCl SFI增加約<strong>5% </strong>Overhead,而在x86_64平台上增加約<strong>7%</strong>的執行Overhead.相對於原本基於x86平台的CFI技術 (可參閱下表來自 “Native Client: A Sandbox for Portable, Untrusted x86 Native Code ”論文中的測試數據),可以發現在x86平台上如果是基於硬體支援Segment Register的CFI技術,多數的情況大概都只有2%左右的Overhead.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2Cecwf9zweK2SJ_CUs11LQPbZg4MNqwik-xh4jPAZdeoQm8rA8sqlKypX8kLxfMijuG2wgcTd6Sd2hj2Y8rOjXPlWVQjmczyI6NWnGITo0nbpTnoS3zv6fxARMQ0KFuo5PgzdWPr3_Wg/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m2b9f19ea%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="397" data-original-width="453" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2Cecwf9zweK2SJ_CUs11LQPbZg4MNqwik-xh4jPAZdeoQm8rA8sqlKypX8kLxfMijuG2wgcTd6Sd2hj2Y8rOjXPlWVQjmczyI6NWnGITo0nbpTnoS3zv6fxARMQ0KFuo5PgzdWPr3_Wg/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m2b9f19ea%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x86 32bits版本的CISC Fault Isolation方案,主要有以下的特點</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,Code Section為Read-Only Statically Linked.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,Code Section必須是32bytes Alignment (也就是說每個函式的起點一定是 32bytes Alignment,而函式結尾也一定會Padded到32bytes Alignment.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,在Code Segment內可被執行到的處理器指令,在啟動時都會經過Native Code檢查程式驗證無虞後才執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,所有非直接的程式碼流程跳躍 (例如要經過暫存器的運算才得到目標記憶體位址),都會被一組指令集所取代,用以確保在Run-Time時,最後所要跳過去執行的Target Address是落在合法的範圍內.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="804">10002e7: 83 e1 e0 and $0xffffffe0,%ecx<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10002ea: ff e1 jmp *%ecx</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,會確保沒有任何處理器指令操作,可在執行時期跨越UnTrust Code所許可的記憶體執行範圍</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
查核原則會在程式啟動時進行,負責查核的這段程式會跟NaCl Trust Code Base(TCB) 整合在一起成為Native Client Run-Time System的一部分. x86 32bits的CFI方案會利用x86 Segment Registers作為執行階段的Sandbox效能改善的一部分.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Paper ‘Efficient Software-Based Fault Isolation’中有介紹到兩種Software Fault Isolation的實作方式,分別為Segment Matching與Address Sandboxing, 筆者分別加以說明如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,Segment Matching (</strong><strong>其實就是</strong><strong>CFI</strong><strong>的概念</strong><strong>):</strong>可針對不安全的Store對記憶體寫入或與處理器Program Counter有關的Jump/Branch跳到新位址執行的指令進行靜態指令集查核,確保是在所設定的保護記憶體Segment內.靜態檢查只能針對寫入記憶體與跳過去執行指令時是採用預先定義好的記憶體資料或指令位址的寫法,若是把資料或指令所在的記憶體位址先寫入到暫存器,並且必須要經過一些運算得到最後所在的記憶體位址時,靜態檢查就無法在這狀況下提供如預期的效益. 因此,如果針對上述寫入記憶體與執行指令的動作前,先加入Checking Code,用以檢查最後所要去寫入或執行的記憶體位址是否超過目前模組所在的Fault Domain,若超過, 則針對這軟體模組觸發System Trap Error,這樣的技術就稱為Segment Matching.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在RISC架構下 (使用記憶體資料時,必須要透過Load/Store指令),Segment Matching支援一個記憶體查核的動作至少需要四個Dedicated Register 暫存器機制參與.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一個用來記錄Code Segment,一個記錄Data Segment,一個儲存Segment Shift Bits,一個儲存Segment Identifier.基於這樣的限制,也就必須要透過編譯器的支援,在產生UnTrust Module的編譯結果時,就必須要把希望避開的暫存器在編譯階段進行處理,並在效能上加以優化.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
必須在所有UnTrust Module中都不可以使用到的暫存器,只限定給所插入的Check Coding中使用,若沒有這樣的限制,會有機會讓UnTrust Code跟Checking Code都使用到同樣的記憶體位址查核暫存器,且UnTrust Code也可以修改到這個暫存器,而導致防護上的遺漏.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一個基於這四個Dedicated Registers的Segment Matching稽核流程為</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="819">1,把所要寫入(Data)或產生Jump/Branch(Code)動作的Target Address 寫入Data/Code Dedicated Register<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, Data/Code Dedicated Register >> Segment-Shift Dedicated Register 的結果寫入任意可用的暫存器A中.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,比對A是否符合 Segment-Identifier Dedicated Register</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,如果Target Address經過 Right-Shift 結果與 Segment-Identifier Dedicated Register 不符合,表示Target Address超過UnTrust Module所應該要寫入或執行的有效記憶體範圍外,如此則觸發System Error Trap以進行後續處理</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,如果比對後確認Target Address是在UnTrust Module有效寫入或執行的記憶體範圍內,就以Target Address所儲存在的Data/Code Dedicated Register進行後續寫入或執行所用位址暫存器.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Segment Matching優點在於能針對要防護的指令加以防範,能有效的降低軟體執行的Overhead. 除了基於Target Address在Right-Shift後與Segment Identifier比對Illegal Address的機制外,Address Sandboxing能提供不同的機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,Address Sandboxing (</strong><strong>其實就是</strong><strong>SFI</strong><strong>的概念</strong><strong>)</strong><strong>:</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據這篇論文的設計,Address SanBoxing會需要有五個Dedicated Registers (比Segment Matching多出一個),兩個用來儲存Code/Data Segment Identifier,一個儲存Segment And-Mask (用以作為 & 把Target Address Segment區塊給消掉),兩個用來儲存經過Sandbox處理後要去寫入或執行的Data/Code Address,如下圖所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Data/Code Dedicated Register=</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(Target Address & And-Mask Register) | Segment Identifier Dedicated Register</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJUB6LU3Ek1hoSLMItjAjnKxn1ziJ8etgMO0nV-tXITiqnbqUXma4maOacoCDeKq6UevdeoM0zlZLaiDsfyzSIdJ3J7SrmEQtB0FpOjNwpB77JVDW5g0LZQRF89T_i1PWslrWN4XTIPGc/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_2572851c%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="506" data-original-width="800" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJUB6LU3Ek1hoSLMItjAjnKxn1ziJ8etgMO0nV-tXITiqnbqUXma4maOacoCDeKq6UevdeoM0zlZLaiDsfyzSIdJ3J7SrmEQtB0FpOjNwpB77JVDW5g0LZQRF89T_i1PWslrWN4XTIPGc/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_2572851c%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在CISC Fault Isolation之外,Software Fault Isolation(SFI)技術可解決CFI必須基於CISC 處理器支援的Code/Data Segment Register限制.雖然純軟體方案的SFI具備跨平台性,但每個處理器的指令集也有相當差異,以實際的測試來說,SFI 在ARM的Overhead會比x86更輕,有一部分原因在於CISC/RISC指令集的差異,例如ARM指令是32bits alignment(Thumb 是16bits alignment, Thumb2 則為 16/32bits alignment),而x86 CISC指令會有1 bytes到十幾bytes各種不等長的指令組合,如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">(1bytes)0×48 = dec eax<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(2bytes)0×89 F9= mov ecx,edi</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(7bytes)0x8B BC 24 A4 01 00 00 = mov edi,dword ptr [esp+000001A4h]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(11bytes)0×81 BC 24 14 01 00 00 FF 00 00 00 = cmp dword ptr [esp+00000114h],0FFh</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在unTrust Code 記憶體範圍內執行非直接記憶體的程式碼跳躍或是非直接的記憶體資料存取 (Indirect control flow and memory references),都會被Sandbox過濾,並以組合指令取代. SFI在x86上會基於MMU利用Page Protection,避免UnTrust Code有機會去影響到Trust Code.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在UnTrust Data的記憶體範圍,會在前後預留Guard Page,用以避免記憶體Overflow,Underflow與錯置記憶體的問題發生.為確保Source Code Level的可移植性, ARM/x86_64都跟x86_32平台一樣為 ILP32 (32-bits Int,Long and Pointer)的主要資料型別.就算NaCl是運作在64-bits環境下,也會限制NaCl應用只能使用32-bits 4GB的記憶體空間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>SFI (Software Fault Isolation)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要介紹SFI技術,最好的解釋方式應該是程式碼中會有Trust與UnTrust的Code,而這些Trust的Code主要是由平台提供者所撰寫的程式碼,UnTrust的Code則是平台開發者同意讓第三方軟件可以在該平台執行的程式碼,當今天平台提供者希望透過軟體的技術達到在不同處理器硬體上都可以實現保護Trust Code執行與偵測防範UnTrust Code的目的時,Software Fault Isolation技術也就因此誕生了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SFI主要會包括以下的條件</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,在同一塊記憶體空間中,把UnTrust Code/Data搬到邏輯上劃分給UnTrust Code/Data的區域.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,透過程式碼的查核,找出UnTrust Code中嘗試寫出或是跳出UnTrust Code所配置邏輯記憶體範圍的位置,並加入檢查機制的程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SFI 整體概念如下圖所示,傳統上習知的Trust Code是Kernel Space,但在SFI技術下,同一個Process內部又可以劃分出屬於平台/Framework/Service的Trust Code與屬於第三方應用的UnTrust Code,彼此的交互呼叫則可透過SFI技術來實現.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimeSsxJURlDsnDN28INihnBZb5oq9vkX_iKuOP2UnDO7ipaMKYMSJAemtX5p5HFgU3pGbvCADxGcP7GG-Iin7iVp7ORu1UjYJvbIbs4AXUNDH09IR9Ed9UZW6hgxjCGwzeCYcPkhg5A0Q/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m2e096ab6%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="463" data-original-width="800" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimeSsxJURlDsnDN28INihnBZb5oq9vkX_iKuOP2UnDO7ipaMKYMSJAemtX5p5HFgU3pGbvCADxGcP7GG-Iin7iVp7ORu1UjYJvbIbs4AXUNDH09IR9Ed9UZW6hgxjCGwzeCYcPkhg5A0Q/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m2e096ab6%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">如下圖所示 (參閱自 Software Fault Isolation (at CS Language-Based Security,January 23, 2008)),在同一個UnTrust Code內的程式碼是可以彼此呼叫的,若是有跨Domain的呼叫時,透過Jump Table的機制讓函式的呼叫,函式的返回在跨Domain間都是間接的呼叫與返回,藉此可以透過 Trusted Call/Return Stub機制進行稽核的動作,而在Run-Time時,就可以去稽核程式碼,避免有跨出Jump Table以外的呼叫/返回可能.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3eygeY9jg0RWDIJH0j07HTl7GEiHbJseRe0FadnDorhXoOOQvBVzQAOjGmr_631Yb-IUadLNjNMqWWJmrMIdCeX10YVvjhq1kQVOR-5-jgm1DQjYsaGvJimzk7te1HLeGrwEDpH6sGsA/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m50389ce1%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="553" data-original-width="800" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3eygeY9jg0RWDIJH0j07HTl7GEiHbJseRe0FadnDorhXoOOQvBVzQAOjGmr_631Yb-IUadLNjNMqWWJmrMIdCeX10YVvjhq1kQVOR-5-jgm1DQjYsaGvJimzk7te1HLeGrwEDpH6sGsA/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m50389ce1%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來讓我們根據Google Native Client SFI的實現加以介紹.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>NaCl SFI</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Native Client主要基於Browser,讓Browser Based的應用應用能以原生應用程式效能運作的目的之用. 並提供Software Fault Isolation Run-Time的安全管理機制,讓應用程式可以呼叫所需的系統服務,但又不減損安全性.基於希望解決目前Browser-based Application的效率問題 (目前被廣泛應用的Browser-Based Application開發語言為Java Script),像是微軟所推出的ActiveX 或 NPAPI 以Browser Plug-in模組的方式提供Native Code層級的效能執行</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於此Native Client希望提供一個安全的框架,把基於網頁的原生碼應用程式Native Code分為兩個部分,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,屬於Native Code受限的執行環境,以預防不合法的操作所帶來的副作用</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,屬於Host端提供的Run-Time Native Code安全執行環境,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可參考如下示意圖,一個網頁的應用程式,其中 HTML/JavaScript與該網頁上所提供的Native Client APP由於是透過網頁下載,會被定義為UnTrust 的程式碼,而本機所提供的Run-Time Framework包括後端的儲存機制,由於是基於本機所提供的服務,會被定義為Trust程式碼. 上層的HTML/JavaScript.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Native Client APP是具備可跨到不同平台與執行環境的能力 (基於底層Run-Time Framework的提供).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ActiveX最大的差別是,ActiveX是透過GUID與憑證去驗證該Native Code應用程式是否為可信賴的,若不具備可靠的憑證,就會跳出警告的對話盒讓使用者自行判斷 (雖然多數使用者並不具備判斷的能力),但Native Client是把稽核的工作交給NaCl container進行,也就是說使用者端並不會收到警告的對話盒.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZCkGnNO_SrTV8p6AHF-tT6uKnaBQaM2-Z-NXsXCp1XwPkJodcjE71CArtc0lz0t9egM7TOp_f-ghdHvgn9r0dXiy1mwFR0eKnkiXVCjzTu9nMbODR4NT4XpXl-PLoJ0ZcKGj3eQIlhPY/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m66498b72%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="545" data-original-width="801" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZCkGnNO_SrTV8p6AHF-tT6uKnaBQaM2-Z-NXsXCp1XwPkJodcjE71CArtc0lz0t9egM7TOp_f-ghdHvgn9r0dXiy1mwFR0eKnkiXVCjzTu9nMbODR4NT4XpXl-PLoJ0ZcKGj3eQIlhPY/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m66498b72%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每個模組間都會在自己獨立的記憶體範圍內,跨模組的溝通會基於Native Client的IMC (Inter-Module Communications)機制,以上圖來說,HTML/JavaScript跟Native Client會透過Simple RPC或NPAPI(Netscape Plugin Application Programming Interface)溝通,而資料的傳遞則基於Shared Memory或Simple RPC的IMC機制來進行,一個應用程式所需基於 libc.so..etc的 Run-Time Framework(像是Memory/String/Storage/POSIX Thread interface, Mutexes, Semaphores..etc)有關的APIs,則由底層的Run-Time Framework提供,每個NaCl模組間的溝通也都必須要透過IMC,而不允許直接的資料傳遞,以避免可能的安全性問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一個Native Client能執行自己所在所驗證過的Code Segment,與透過NaCl API去使用Run-Time Service,並經由InterModule Communication Interface傳遞資料,亦可malloc記憶體與產生新的Thread (但不可產生新的Process.).在經過程式碼稽核後, Native Client App才得以繼續執行,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Native Client Run-Time</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當瀏覽器要去下載一個Native Client網頁時,會把包括網頁內容與NaCl 執行檔.NEXE檔案下載到本機電腦來,如下圖所示, Chrome在下載.NEXE檔案後,以筆者的Windows 64bits電腦來說,會啟動nacl64.exe作為Native Client .NEXE執行檔的載入程式</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn-r05_xVhRvbo-ibdQV428W3DAkty6vW0nUJ2dEwBqyPwDIici_kQBWBCjw3YsfgiNF-4UtlkLsNeCNqs3Pw7jF_fAOhk0E9DHKm8xfxFK4DnaTb07fvkYhHLFp6os-ze6lKWDP2QWq0/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_4bbbce2c%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="317" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn-r05_xVhRvbo-ibdQV428W3DAkty6vW0nUJ2dEwBqyPwDIici_kQBWBCjw3YsfgiNF-4UtlkLsNeCNqs3Pw7jF_fAOhk0E9DHKm8xfxFK4DnaTb07fvkYhHLFp6os-ze6lKWDP2QWq0/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_4bbbce2c%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">而在下載的網頁內容中,會包括一個Link指到NMF檔案,這個NMF檔案會包含有關執行檔案.NEXE的MetaData,會包括這執行程式的Dynamic Linker .So與在執行過程中所需要用到的.So動態函式庫.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmMWNLyPKrVsmVhLDbmSOWR_CPJfIcFZ5kuERC8Rbopc_Pl6dWr8IBHKeTr4rOH6W7RcU9Cz2WfWFhfx3EEy3rqUxNJ9EKXYHOJ6xQlfbp-_lAemji8yXz0axflgF8NeM_z_h2tQLyxL8/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_44810eac%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="588" data-original-width="678" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmMWNLyPKrVsmVhLDbmSOWR_CPJfIcFZ5kuERC8Rbopc_Pl6dWr8IBHKeTr4rOH6W7RcU9Cz2WfWFhfx3EEy3rqUxNJ9EKXYHOJ6xQlfbp-_lAemji8yXz0axflgF8NeM_z_h2tQLyxL8/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_44810eac%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據.NEXE的MetaData在Native Client啟動過程中,就會根據本機電腦的處理器資訊,例如筆者電腦為Windws 64bits就會下載hello_loda_x86_64.nexe NaCl執行檔,並會下載有關的.So,如下所示對應的檔案下載後,會儲存在使用者電腦的 AppData\Local\Temp下,以筆者驗證的環境為例,這些檔案會被Rename為不同的.Tmp檔案 (例如 6934.Tmp 其實就是libc.so.3c8d1f2e,而6901.Tmp其實就是 hello_loda_x86_64.nexe主執行檔.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6934.Tmp (=<strong>libc.so.3c8d1f2e</strong>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6922.Tmp (=<strong>libdl.so.3c8d1f2e</strong>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6933.tmp (=<strong>libgcc_s.so.1</strong>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6912.tmp (=<strong>libpthread.so.3c8d1f2e</strong>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
67D8.tmp (=<strong>runnable-ld.so</strong>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
66AE.tmp (=<strong>hello_loda.nmf</strong>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6901.Tmp (= <strong>hello_loda_x86_64.nexe</strong>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
整體概念如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPkICrlOodMX4w0DKXL6uU9cUlc3u_WScxGN871Uiug2vB9jfiTvjGhNYOOi400FF9ILD-QtiAVnvMgFfIEMib7J2v8fQbdcFtUwIe8SuiNatZHaoqs2K9ESrYNvoRe15oedsdtwmEC2c/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m387593%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="335" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPkICrlOodMX4w0DKXL6uU9cUlc3u_WScxGN871Uiug2vB9jfiTvjGhNYOOi400FF9ILD-QtiAVnvMgFfIEMib7J2v8fQbdcFtUwIe8SuiNatZHaoqs2K9ESrYNvoRe15oedsdtwmEC2c/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m387593%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">如果把.NEXE執行檔,與所需的階層.So以彼此的Dependency 畫成階層關係圖,可以參考如下圖所示</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYJr-NIO8RxA5HVJ65Cmg47Vu4DRUpE72vDS49Nsm_SWJy_Y2REzF1-PvR9JtupKi8YscLUQWze8sZT0GApQxS4yePuMKGc5J2gHi1bQo89s9qka5xMn9hCGlvVYyqXpVCwTsjKc4bFss/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m202ab6f7%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="243" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYJr-NIO8RxA5HVJ65Cmg47Vu4DRUpE72vDS49Nsm_SWJy_Y2REzF1-PvR9JtupKi8YscLUQWze8sZT0GApQxS4yePuMKGc5J2gHi1bQo89s9qka5xMn9hCGlvVYyqXpVCwTsjKc4bFss/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m202ab6f7%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其實在驗證的過程中,包括這些 .So檔案的下載其實都不小,例如 libc.so.3c8d1f2e約9.8MB,而runnable-ld.so約1.1MB,而這兩個卻又是一個Native Client執行環境的基本元素,以網路頻寬而言,實在覺得Native Client的執行成本似乎也太高了……@@@@</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以技術而言,Native Client SFI SandBox真的是一個很棒的方案,但雖然Google已經為PNaCl預備了ARM的執行環境,但以所需下載的檔案成本而言,對以ARM為主的手持裝置(多數為手機),在這部份似乎還有很大的改善空間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Native Client SandBox</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Native Client的SandBox可以分為Inner SandBox(binary validation)與Outer SandBox (OS system-call interception),如下圖所示,其中 Inner Sandbox主要負責在編譯程式碼的過程中,透過靜態分析(static analysis) 屬於UnTrust區間的程式碼,確認沒有指令對合法記憶體位址外的寫入與執行動作,定義查核的Rules,針對Stack Pointer,函式呼叫,返回,與對記憶體的讀寫操作使用的記憶體位址進行稽核的程式碼產生.在x86平台上,還會利用Data與Code Segment Registrs的特性(這是ARM處理器上所沒有的),透過處理器硬體限制Data與Code的記憶體參考範圍,以降低對效能的影響.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但程式碼畢竟是在開發者的電腦上所產生的結果,如果開發者也理解inner sandbox對於這些操作程式碼的原理,其實還是有很大的機會被破解. 也因此在Run-Time過程也有一層outer sandbox機制,針對使用者透過內嵌Assembly,或透過二進位方式把執行碼植入的手段進行稽核,例如刻意在程式碼中加入直接對作業系統System Call呼叫的機制,在此就會被稽核,而導致程式無法正常執行.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXZApl2pHimhkmHP4XzwF0bK5xbbSfLQanXVKoYvHeWlHdOJvYeVga95jka_OCJtpBeRfusQ9vmVcjMl2m2DZMHAoROuHPDapj1iueukiixjAbI1gmYz6osyblSHUp7Ns0S2fTdABNz2A/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_612ab342%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="430" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXZApl2pHimhkmHP4XzwF0bK5xbbSfLQanXVKoYvHeWlHdOJvYeVga95jka_OCJtpBeRfusQ9vmVcjMl2m2DZMHAoROuHPDapj1iueukiixjAbI1gmYz6osyblSHUp7Ns0S2fTdABNz2A/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_612ab342%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於Inner SandBox,一個x86 Native Client執行檔在執行指令上會有以下的限制</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,不能直接使用syscall 與int指令去呼叫作業系統提供的System Call</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,不能直接使用會影響到x86 Segment狀態的指令集,像是lds, far calls..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,函式結束時,不會使用ret指令,而是會透過jmp藉由包裝過的機制,返回呼叫者</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,禁止所有需要特權等級的指令或 hlt指令.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,不支援Hardware Exception ( Segment Fault,Floating Point Exception)與外部中斷的處理</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,支援 C+ 的exception,但不支援只有在Windows平台才支援的SEH (Structured Exception Handling)應用程式例外處理機制. (這機制在Windows以外平台並不支援.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,Native Client程式碼一旦載入到記憶體中,就會透過OS層級的保護機制,設定該區塊記憶體在執行時期為不可寫入的狀態. (在linux下可透過mprotect把記憶體設定為不可寫入)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,會進行”control flow integrity”的查核,確保在程式碼執行的Flow中,所要前往執行記憶體位址所在的指令都是有效指令.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9,提供如下nacljmp的組合指令,進行程式碼的呼叫流程.在x86上的nacljmp實作如下所示,會確保所有指令的jump都是32bytes alignment</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="448">X86_32:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
and $0xffffffe0,%ecx</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jmp *%ecx</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="448">X86_64:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
and $0xffffffffffffffe0,%r11d</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
add %r15,%r11</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jmpq *%r11</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10,程式碼的Validator會確保Data Integrity,沒有載入或寫出資料在許可記憶體範圍外的動作,要執行的代碼都是可以被反組譯的 (Reliable dis-assembly)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而Outer SandBox指的是應用程式在Run-Time執行時,透過作業系統System Call,或是刻意透過Run-Time Service漏洞來執行不合法行為的動態執行時期稽核機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>x86_64 SFI Inner SandBox</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Google文件,在x86_64與在ARM平台上提供SFI技術開發所遇到的問題多數的情況都很類似,只有在一些細節上會有很大的差異,例如: 在ARM平台上一個有效的Data Address前後會加上Guard Region,且ARM平台上的SFI是簡單以是否在1GB以下的範圍來區分是否為UnTrsut Code或Trust Code.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但在x86_86方案中就不是以如此簡單的方式來做區別.x86平台從32bits演進到64bits,在暫存器的使用命名有一個基礎上的變動,例如: AX 暫存器指的是16bits AX暫存器,而 EAX指的是32bits AX暫存器,而RAX指的是64bits AX暫存器.以及並在x86 bits環境下提供了八個新的通用暫存器 (General Purpose Registers).並透過修改 RSP(Stack Pointer)與 RBP (Base Pointer)來確保所要存取的Data Address都是在合法的記憶體範圍內.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x86_64環境並不像ARM一樣只用1GB記憶體以內為邊界來判定是否為UnTrust Memory,每個x86_64上的UnTrust Code應用程式會認為自己可以Access完整4GB的記憶體空間,但是在ARM上的UnTrust Code則認為自己只有0-1GB的有效記憶體空間可以被使用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據Google文件,x86_64 Native Client環境會遵循以下原則</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,UnTrust/Trust Module每個所配置到的記憶體空間都會跟4GB範圍對齊,並在前後各預留 10x4GB的記憶體空間,作為Protected/Unmapped Region</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,x86_64的r15暫存器,被定義為Designated Register RZP<strong>(Reserved Zero-address base Pointer)</strong>,會被初始化指到一個4GB Aligned base address作為對應模組UnTrust Memory空間的起點,對UnTrust Code而言這個暫存器會是唯讀的</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,對RIP暫存器的寫入動作都會是 RZP的</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
為了確保 RSP/RBP 所包含的Stack Address都是有效的記憶體位址,會有以下的操作限制</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,RBP可以被修改,藉由從RSP以沒有Masking的方式進行拷貝動作</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,RSP可以被修改,藉由從RBP以沒有Masking的方式進行拷貝動作</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,其它對RSP/RBP暫存器的修改動作,則必須透過一組SFI虛擬指令進行,以便對目標記憶體位址進行Mask,確保目標記憶體位址是在合法的範圍內.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於此,一個有效的RSP暫存器操作會以如下組合指令進行,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="804">10001e0: 8b 2c 24 mov (%rsp),%ebp<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10001e3: 4a 8d 6c 3d 00 lea 0x0(%rbp,%r15,1),%rbp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10001e8: 83 c4 08 add $0x8,%esp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10001eb: 4a 8d 24 3c lea (%rsp,%r15,1),%rsp</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如,add $0x8,%esp 就可以確保RSP 64bits長度的內容,最高的32bits會被Clear,以便ESP會限制在所許可的32bits範圍內.而R15會等於目前這個SFI Native Client所被允許的64-bits位元內所配備置的32-bits 4GB範圍.由於限制了RSP必須在有效的4GB範圍內,因此像是對暫存器操作的Push/Pop或 near call指令就可省去額外的確保動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關RSP暫存器的操作與 GCC跟pnacl-clang兩者編譯後結果的比較,可以參考如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG5JXMol-yX28XieXuFgyBG1SkqGjqh3sVTolx7o5wjbDomKANLbYArrYoA9xzabECIow82nkN_77AJa5zFKUVuEIcUOXoPf254nHrDK5NsDRBXcKjx9M__ahVaiuNfui4cRucCetd9i4/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m1fc734ca%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="321" data-original-width="756" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG5JXMol-yX28XieXuFgyBG1SkqGjqh3sVTolx7o5wjbDomKANLbYArrYoA9xzabECIow82nkN_77AJa5zFKUVuEIcUOXoPf254nHrDK5NsDRBXcKjx9M__ahVaiuNfui4cRucCetd9i4/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m1fc734ca%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以看到函式的入口一定會是32bytes Alignment,且會把64bits RSP 高位址32-bits給清掉,並基於x86_64上的R15暫存器來限制RSP應用在指定的64bits 的 32-bits 4GB記憶體範圍內.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關函式呼叫的動作,如下所示同樣以 GCC跟pnacl-clang兩者編譯後結果的比較,可以看到若基於Function Pointer呼叫時,若以RAX暫存器為最後函式呼叫的位址,在正式呼叫前會先透過 and 確認eax一定是32byte Alignment且高位址的32bits會清為0,最後同樣會透過x86_64上的R15暫存器來限制RAX在指定的64bits 的 32-bits 4GB記憶體範圍內.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6A9MTV1DZEG6xi6xPe876zWYkOFTLzvnJmaKeCq6l5GJGF5IQgxuasAuiDO4lX00r_Qc2gdN6p5arKSIbGzeVudde8-aeGKIKqCSwPKcNdiZzF3DzaQeWR2RlwHnPDvL3sRuNUxidmVg/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_6fccc3f1%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="409" data-original-width="863" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6A9MTV1DZEG6xi6xPe876zWYkOFTLzvnJmaKeCq6l5GJGF5IQgxuasAuiDO4lX00r_Qc2gdN6p5arKSIbGzeVudde8-aeGKIKqCSwPKcNdiZzF3DzaQeWR2RlwHnPDvL3sRuNUxidmVg/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_6fccc3f1%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">有關函式呼叫的動作,如下所示同樣以 GCC跟pnacl-clang兩者編譯後結果的比較,可以看到若基於Fnction PLT (Procedure Linkage Table)呼叫時,會把PLT Table呼叫入口置入一組程式碼,並藉此確保R11暫存器函式呼叫的位址,在正式呼叫前會先透過 and 確認R11一定是32byte Alignment且高位址的32bits會清為0,最後同樣會透過x86_64上的R15暫存器來限制R11在指定的64bits 的 32-bits 4GB記憶體範圍內.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpI96wqfxKlmC7F8HE9C9QvgXjXLzYU4QNmj1L5D3sWynckf9w2cCeUqSu6THxx-AKLvj7rrN6nT_0yw5lxHigqaSQcwoaF4hlI_FZP7aP2q0BA1skvi1Lc5nEgJZbYUi0HIfDhLeoOaY/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_6b01c2f9%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="410" data-original-width="876" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpI96wqfxKlmC7F8HE9C9QvgXjXLzYU4QNmj1L5D3sWynckf9w2cCeUqSu6THxx-AKLvj7rrN6nT_0yw5lxHigqaSQcwoaF4hlI_FZP7aP2q0BA1skvi1Lc5nEgJZbYUi0HIfDhLeoOaY/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_6b01c2f9%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">有關函式呼叫的動作,如下所示同樣以 GCC跟pnacl-clang兩者編譯後結果的比較,可以看到若是在UnTrust Code範圍內的呼叫,就會直接呼叫而無需再透過額外的查核動作.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrwRKHzxfQ4cS87ySUBHyUWEyYYr0mJ-QChTyGsjJgLJmn6WxZJi0LJvs8CwCdcHZH-DuJMkQH77X8XPChlYmb0O3AAy0ftxTJ06dYGUBpJg2EAxqpG7-ZuRnUKKFr8cg23ReP_ovg2ug/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_145630d9%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="348" data-original-width="865" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrwRKHzxfQ4cS87ySUBHyUWEyYYr0mJ-QChTyGsjJgLJmn6WxZJi0LJvs8CwCdcHZH-DuJMkQH77X8XPChlYmb0O3AAy0ftxTJ06dYGUBpJg2EAxqpG7-ZuRnUKKFr8cg23ReP_ovg2ug/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_145630d9%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在記憶體讀寫的操作上,最常見的記憶體位址處理方式為把一個有效的Base Address Register (RSP/RBP或RZP (在這為R15))跟 32-bits Displacement數值進行處理,用32-bits值取代,加上一個32-bits index與一個Scaling Factor,有關的計算邏輯可以參考下面的算式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
basereg + indexreg * scale + disp32</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如如下虛擬程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
add $0x00abcdef, %ecx</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov %eax, disp32(%RZP, %rcx, scale)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉下述實際的記憶體讀寫操作範例來看,包括在對記憶體寫入與讀取操作時,就會透過 像是 ‘mov 0x22(%r15,%rax,1),%al’ 以 ‘basereg + indexreg * scale + disp32’來對記憶體作讀取或寫入,並以R15限定最後存取的記憶體位址是在指定的64bits 的 32-bits 4GB記憶體範圍內.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關x86_64的Function Return操作,如果以RDX暫存器進行程式碼記憶體位址的跳過流程控制的話,就可以下述參考的虛擬程式碼來進行</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%edx = …</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
and 0xffffffe0, %edx</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lea (%RZP, %rdx, 1), %rdx</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jmp *%rdx</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉下述實際的記憶體讀寫操作範例來看,會以RCX確認RCX一定是32byte Alignment且高位址的32bits會清為0,最後同樣會透過x86_64上的R15暫存器來限制RCX在指定的64bits 的 32-bits 4GB記憶體範圍內,以便最後Function Return時一定是在所許可的記憶體範圍內.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUY_OK-P1s3VlxVxHsbLqAd-4VZJOizx8HE1KbLxrsZiwh8f_kX2qaCaeCtqC2yUFihU7J5C_WptA38peJvhOIOrVfT16CREq4t4Je0fvOcNiHsnTQ26iHdfCGfIgpe41-oEsQ2JbdbNA/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m6612a6a7%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="491" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUY_OK-P1s3VlxVxHsbLqAd-4VZJOizx8HE1KbLxrsZiwh8f_kX2qaCaeCtqC2yUFihU7J5C_WptA38peJvhOIOrVfT16CREq4t4Je0fvOcNiHsnTQ26iHdfCGfIgpe41-oEsQ2JbdbNA/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m6612a6a7%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">基於上述的解說,我把x86_64環境下,每個Native Client所用有的4GB Memory Space的概念用下圖表示,我們可以知道透過SFI SandBox機制確保,可以讓在x86_64環境執行的應用能擁有獨立的4GB空間,並會透過R15與64bits暫存器的操作,確保不會被預期外的高位址32-bits操作,導致有溢出4GB記憶體空間的不合法執行行為存在.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ6m__psjrQ5VJcZTf-sSKfL76Xk7fBMV859RnFAtmH3aQ23wSJu3hBR6mTQts6qkaL7rJ-XQsFFy3jh6pZs5l9b59_HpUMQO81JFEuGl-lBCst6jTET33hTrOL2cAzMwEeUldQ_8DoWU/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_4b8181e9%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="390" data-original-width="735" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ6m__psjrQ5VJcZTf-sSKfL76Xk7fBMV859RnFAtmH3aQ23wSJu3hBR6mTQts6qkaL7rJ-XQsFFy3jh6pZs5l9b59_HpUMQO81JFEuGl-lBCst6jTET33hTrOL2cAzMwEeUldQ_8DoWU/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_4b8181e9%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>ARM SFI Inner SandBox</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以ARM CortexA9 1GHz方案來說,參考Google文件,在啟動SFI機制後,增加約5%的CPU Overhead與20%的檔案大小,其中包括10%的Padding到16 bytes Alignment的成本,而10%為針對非直接的記憶體寫入與非直接的程式碼執行路徑所加入的檢查程式碼. (以上的比率, 都會隨著不同應用程式的實作方式差異,導致SandBox處理結果不同,而有所改變).</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEQiCBQ-9_spBL004k-Hr9u6dR5CEnPlcTVNTmDTbskN7H4qYN1yAAiR2PCZRAVGr6DEDuMmGNDnVWnRcdKfKmC4GKU7U6XNF8AqwCpiyV5TOt_DkLqnwsDWLAzdbb-FnLoIUdHzahpLQ/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m3c4c6527%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="408" data-original-width="591" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEQiCBQ-9_spBL004k-Hr9u6dR5CEnPlcTVNTmDTbskN7H4qYN1yAAiR2PCZRAVGr6DEDuMmGNDnVWnRcdKfKmC4GKU7U6XNF8AqwCpiyV5TOt_DkLqnwsDWLAzdbb-FnLoIUdHzahpLQ/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m3c4c6527%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在ARM平台上,SFI目前只支援ARMv32而不支援有 Thumb 16bits 或Thumb2 16/32bits並存的指令. 這是基於SFI主要考量的是效率而非Code Density.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,在ARM SFI下,0-1GB是UnTrust Store/Control Flow memory space,在1GB-4GB這3GB範圍是屬於 Trust Run-Time與作業系統區.但在x86_64上,並不限制UnTrust Code讀取1GB以外的記憶體 (但不能溢出SandBox所指定的範圍.),在ARM平台上會,SFI會包括</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,確保所有的UnTrust Code不能執行任何被禁止的指令. (Undefine Instruction,Ram System Call)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,確保UnTrust Code不能寫入與執行1GB以上記憶體的資料與程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,確保UnTrust Code不能Jump到1GB以上的記憶體位址</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0avYRfNktVi2zoJPGQoMsxmqqSG8X-WRl1dqZA5vhI607OyhBfd3jYmitYRUZfGi_QPoqaJxEAl_kpvTtBborjad9eIKS0qG50FsLGq0S1a50H9cCQk83Vhd27wLXqNETweZvRdNFcQ0/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m637697a%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="491" data-original-width="455" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0avYRfNktVi2zoJPGQoMsxmqqSG8X-WRl1dqZA5vhI607OyhBfd3jYmitYRUZfGi_QPoqaJxEAl_kpvTtBborjad9eIKS0qG50FsLGq0S1a50H9cCQk83Vhd27wLXqNETweZvRdNFcQ0/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m637697a%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ARM上的實作,SFI SandBox記憶體操作可在一個指令中完成,不需像其它平台的實作要有額外的暫存器 (所以ARM的R0-R15都可以被使用.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ARM版本跟x86支援指令不同之處在於ARMv32支援固定32-bits指令,會以每16bytes Alignment (四個ARMv32指令)長度進行處理.非直接程式碼/資料存取的Control Flow會以每個16bytes的bundle為單位.由於ARM Code的區塊也會Embedded 部分 Data with Code Segment,為避免該區域有機會導致程式流程跑過去執行的問題,在會Data Bundles的起點位址加入一個無效指令集.(bkpt 0x7777)去避免執行到這部份的Data.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果執行到一個直接的Branch(記憶體位址直接指定),就會直接確認所Branch過去的記憶體位址所在是否為一個有效的指令.而對非直接的Branch(記憶體位址需要經過額外的計算處理,最後才透過ARM Program Counter (=r15)進行執行Branch的跳躍).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
We forbid most of these instructions2 and consider only explicit branch-to-address-in-register forms such as bx r0 and their conditional equivalents.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
針對要跳躍過去的記憶體位址可以透過ARM Bit Clear (bic) 指令進行處理,限制UnTrust Code可以在1GB以下低位址區域中執行.如下為一個透過 r1 的 SandBox Branch虛擬指令.可用以確保在ARM上Branch的位址必須是在1GB以內,並且每個Branch過去執行的程式碼記憶體位址都是16bytes alignment.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="804">1e8: e3c1113f bic r1, r1, #-1073741809 ; 0xc000000f<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1ec: e12fff31 blx r1</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉下述實際的操作範例來看,這是一個在ARM上取Function Pointer到變數f1後,跳過去執行的例子,其中會透過bic (Bit Clear)指令確保R1一定是16byte Alignment且在1GB記憶體位址以下所許可的記憶體範圍內.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqn3Lrm1zm-QRZ8Z49jrPZ0LUbAJA1dsNZja0pDF8Pj0WGDcfR5sv6RxCUH3wXd_6ZfhtXi-_D1lI7amzsU6zf88pgBKDDLW5gk7OWWY_2hKD5P_8U05y5Pv7SwacWbX31j3QKWwQ2WjY/s1600/image024%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="456" data-original-width="1182" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqn3Lrm1zm-QRZ8Z49jrPZ0LUbAJA1dsNZja0pDF8Pj0WGDcfR5sv6RxCUH3wXd_6ZfhtXi-_D1lI7amzsU6zf88pgBKDDLW5gk7OWWY_2hKD5P_8U05y5Pv7SwacWbX31j3QKWwQ2WjY/s1600/image024%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於安全性的考慮,一般ARMv32會使用的pop {pc}寫法是不被允許的,以免被故意塞入惡意的返回位址,讓ARM SFI SandBox函式返回時形成安全漏洞.會先把要返回的位址儲存在LR中,經過Bit Clear指令確保返回位址是在1GB以下且16bytes alignment,才進行Branch操作,可參考如下範例程式</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="804">210: e28dd010 add sp, sp, #16<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
214: e3cdd103 bic sp, sp, #-1073741824 ; 0xc0000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
218: e8bd4800 pop {fp, lr}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
21c: e320f000 nop {0}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
220: e3cee13f bic lr, lr, #-1073741809 ; 0xc000000f</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
224: e12fff1e bx lr</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(LR </strong><strong>是一般</strong><strong>ARM</strong><strong>處理器上用來記錄返回位址的暫存器</strong><strong>),</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉下述實際的操作範例來看,這是一個在ARM上Function 執行結束後準備返回的例子,其中會透過bic (Bit Clear)指令確保LR一定是16byte Alignment且在1GB記憶體位址以下所許可的記憶體範圍內.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0kAZmcVVEmCOfrfid0re5TOVRvRR5K-Ha7eusOy5Wbj5OOGVN7Kry-nn4pULcGQwiBib_AQqKpwTCI4_N_-1C6KyhQ8vC7iSgWHmOtayy3rusqwuxaPTqHdRSR4APOmYITjXelKtBh18/s1600/image025%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="499" data-original-width="1188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0kAZmcVVEmCOfrfid0re5TOVRvRR5K-Ha7eusOy5Wbj5OOGVN7Kry-nn4pULcGQwiBib_AQqKpwTCI4_N_-1C6KyhQ8vC7iSgWHmOtayy3rusqwuxaPTqHdRSR4APOmYITjXelKtBh18/s1600/image025%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在記憶體寫入的動作上,會確認要寫入的記憶體位址是小於1GB,並且寫入的記憶體位只是沒有Memory Alignment的限制.以目前的實作會透過ARM test指令來做確認,如下參考程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
tst r0, #0xc0000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
streq r1, [r0, #12]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就像是Bit Clear,Test指令會檢測所要寫入的記憶體位址(而且不會修改r0中的內容),如果確定是小於1GB 就會在下一個ARMv32 Condition指令決定是否要讓 Store動作可以真的把資料寫入到目標記憶體位址中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉下述記憶體讀寫實際的操作範例來看,這是一個在ARM上透過R0取得最後讀寫記憶體位址的例子,其中會透過bic (Bit Clear)指令確保R0一定是在1GB記憶體位址以下所許可的記憶體範圍內.(記憶體的讀寫就不用確保16 bytes Alignment了.)</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOS1_MH0lE2ZRtotMhTA4oI1T22f7569e6vUF5xHzjpFW_ViBcfaDBwSPWFHEqd67fE97gwMGhyphenhyphenWoDClG2LPTRMTeaoPPLrO95NdyecLVaDTtWcEseSULXo421yc_tklZZHsbNkuIaPno/s1600/image026%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="664" data-original-width="1150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOS1_MH0lE2ZRtotMhTA4oI1T22f7569e6vUF5xHzjpFW_ViBcfaDBwSPWFHEqd67fE97gwMGhyphenhyphenWoDClG2LPTRMTeaoPPLrO95NdyecLVaDTtWcEseSULXo421yc_tklZZHsbNkuIaPno/s1600/image026%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對儲存在Stack中的區域變數寫入資料,是程式執行過程中經常會遇到的情況.也因此針對Stack Pointer所指位址寫入與判斷這個Stack Pointer是否指向一個有效的Data Address (通常 Process Stack Address都會落在高位址),會是ARM SFI需要直接面對到的問題,也因此會在UnTrusted Progeam初始化時確認SP是一個有效的記憶體位址(小於1GB),如果透過指令自行更新Stack Pointer,若該記憶體位址為無效位址,就會產生一個Fault,若指令有直接更新SP暫存器的動作,就會被SandBox以以下的指令進行修正,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov SP, r1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bic SP, SP, #c0000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉下述實際的操作範例來看,這是一個在ARM上Function 的進入點,其中會透過bic (Bit Clear)指令確保SP一定是在1GB記憶體位址以下所許可的記憶體範圍內.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi18B4_Cql53SLYKuZAS8Z71PERMUbh7Eafse5CVICr_vTSnjbz0o95UD95inwL8Ut_joSlvqc4UeZIel6ohXj2jeJHA5cHZkLP6Fdv77u-BBFMz0WTfzLKAqBUsajHKYf2ql-mn3wwXvg/s1600/image027%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="465" data-original-width="1166" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi18B4_Cql53SLYKuZAS8Z71PERMUbh7Eafse5CVICr_vTSnjbz0o95UD95inwL8Ut_joSlvqc4UeZIel6ohXj2jeJHA5cHZkLP6Fdv77u-BBFMz0WTfzLKAqBUsajHKYf2ql-mn3wwXvg/s1600/image027%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
介紹至此,我們應該已經把x86 64 bits與ARM這兩個常見平台的Sandbox與實際產生的Machine Code作了說明,接下來讓我們稍微在比較一下其它類型的方案以及SDK上實際的操作演示.<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>User-ID based Access Control</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel原本就會根據不同使用者的帳號去進行權限的保護措施,例如要去mount一個device,去修改不同帳號所屬的檔案,或是必須要有 root 權限才可以執行的部分System Call呼叫,都會被Linux Kernel基於使用者帳號所管理的安全機制所管控.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
傳統的Windows使用者行為是一個使用者帳號登入後,會用這個使用者帳號安全多個應用程式,每個應用程式的權限都一樣,相對的如果我是一個惡意程式的開發者,既然這些眾多已經安裝的應用程式都是在同一個使用者權限下所安裝的 (更何況該使用者可能是用Local Administrator權限登入的),惡意程式就可以在所被賦予的權限範圍內去修改所要修改的檔案或是去植入所要植入的必要動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android上的應用程式安全管理機制,正是充分發揮Linux Kernel根據不同使用者帳號權限管理機制,會讓每個所安裝的應用程式都會在所對應的App User Id中執行,也就是說要跨到另一個APP所屬的檔案或執行空間時,就會等於是要跨到另一個Linux Kernel User Id權限空間內,而Linux原本在不同使用者權限管理的措施上就已經是很穩固的基礎,Android把APP User Id跟Linux Kernel不同帳號管理機制綁定在一起,就可以確保每個Android應用程式如果要去修改其他Android應用程式時 (等於是另一個User Id權限),所要突破的門檻就會相對更高. 若在Android下有跨Process的IPC需求時,則可以另外透過像是Binder,自行產生的Socket…etc,其他機制來達成.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Trust with Authentication</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Native Client技術之前,微軟的ActiveX技術應該是讓網頁執行Native Code最著名的作法,但ActiveX Control主要的問題在於這是一個基於認證憑證的信賴關係,只要ActiveX取得微軟的憑證,就可以在不警告使用者的前提下,進行安裝.但一旦該應用程式被安裝到使用者電腦後,該網頁應用程式幾乎就等同於一般應用程式一樣,可以進行檔案讀寫與相關的網路通訊.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
,但以網頁內嵌的ActiveX元件來說,在筆者的IE9上安裝時會出現以下的警告訊息,也因為這樣的警告訊息,對多數使用者而言,其實也不知道所按下的 ‘允許’ 是同意了怎樣的Native Code應用程式在本機執行,但又基於這些警告的對話盒訊息,會讓一般使用者普遍認知從網頁上下載的原生碼應用程式是不安全的認知.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnOmFfOX1gDgUBpyYkAlWlEAfHz_1uJbGYr8VYqDxoVA2C1igR-YCCrfZQA-I-4ZYgl9TcTpdbGm9MAHo-kM0GujpAKzOubCIvYMkkBgR6RzNTlgDYtgzuwDtek_ey1wQiS1bt14udFEY/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m7a026bfb%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="91" data-original-width="877" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnOmFfOX1gDgUBpyYkAlWlEAfHz_1uJbGYr8VYqDxoVA2C1igR-YCCrfZQA-I-4ZYgl9TcTpdbGm9MAHo-kM0GujpAKzOubCIvYMkkBgR6RzNTlgDYtgzuwDtek_ey1wQiS1bt14udFEY/s1600/NativeClientSoftwareFaultIsolation%25E7%25AD%2586%25E8%25A8%2598_html_m7a026bfb%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以往,要解決這樣的問題通常會把要讓使用者安全的ActiveX元件,先透過Setup安裝包的方式,讓使用者先安裝到自己電腦上,而當瀏覽同樣的網頁,遇到要載入指定的GUID ActiveX元件時,就會因為該GUID所對應的ActiveX元件已經被安裝在本機電腦上,而非經由網頁傳遞下來的,就可以避免這樣的警告訊息.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Native Client SDK</strong><strong>與</strong><strong> Source Code</strong><strong>下載</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就跟Android開發環境一樣,開發者可以選擇自己是要基於SDK的應用程式開發或是要取得SDK Source進行深度的開發工作,同樣的需求,在Native Client中也是如此.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SDK的下載工具為 naclsdk (可以參考網頁https://developers.google.com/native-client/sdk/download),可透過指令naclsdk update下載NaCl SDK版本,與透過naclsdk list檢視目前已經下載的版本.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
NaCl Source Code的下載工具為gclient,若只是PNaCl應用程式的開發者,可以直接下載Native Client開發SDK可至 <a href="https://developers.google.com/native-client/sdk/download" style="color: #666666; font-weight: bold; text-decoration-line: none;">https://developers.google.com/native-client/sdk/download</a> ,下載已經編譯好的NaCl SDK環境(依據SDK差異會有不同pepper版本號碼),ToolChain與NaCl Application範例程式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PnaCl Source Code環境可以透過gclient工具下載.在編譯PNaCl前,可以先到<a href="http://dev.chromium.org/developers/how-tos/install-depot-tools" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://dev.chromium.org/developers/how-tos/install-depot-tools</a> ,根據開發所在的環境,下載depot_tools工具包,其中就會包括 gclient.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="273">同步工具</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="533">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="273">naclsdk</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="533">用以下載編譯好的(Portable) Native Client SDK開發環境,適合一般(Portable) Native Client 應用程式開發者.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="273">gclient</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="533">用以下載(Portable) Native Client Source Code,適合要對Native Client技術有深入探索的開發者.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>編譯第一個</strong><strong>PNaCl</strong><strong>程式</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
gclient config http://src.chromium.org/native_client/trunk/src/native_client</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
gclient sync</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
下載完整Native Client與Portable Native Client Source Code後,需先編譯函式庫與Pepper API header檔案,以筆者環境來說,可先至 ‘/home/loda/nacl/native_client’ 目錄下執行</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl/build.sh sdk newlib</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl/build.sh ppapi-headers</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
即可完成編譯.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
不同於一般常用的make編譯環境,Native Client所採用的 Build 環境為Hammer (<a href="http://code.google.com/p/swtoolkit/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://code.google.com/p/swtoolkit/</a> ),這是一個基於 SCons (http://www.scons.org/)的延伸Build環境, SCons是一個Open Source,基於Python的跨平台編譯環境設定建置的工具,可用以取代一般使用的make. 有關SCons and Hammer編譯環境資訊可參考 <a href="http://code.google.com/p/chromium/wiki/ChromiumSoftwareConstructionSystem" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://code.google.com/p/chromium/wiki/ChromiumSoftwareConstructionSystem</a> 與 Building and Testing the Native Client Trusted Code Base(<a href="http://www.chromium.org/nativeclient/how-tos/build-tcb" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.chromium.org/nativeclient/how-tos/build-tcb</a> ).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在PNaCl架構下,基於LLVM執行檔可以分為以下三類</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="330">檔案格式</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="330">.bc</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">Bitcode object file. (Analogous to a plain object file)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="330">.pexe</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">Bitcode executable. (Analogous to an executable file)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="330">.pso</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">Bitcode shared object. (Analogous to a shared object file)</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除了一般BinUtiles的工具,像是pnacl-clang/clang++/ld/ar/nm/ranlib/strip/as,同時PNaCl還提供pnacl-translate可用以把PNaCl BitCode反組譯回Native Code.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以筆者透過gclient所下載的Source Code環境來說,可以在native_client目錄下找到對應到筆者開發環境的Linux x86_64 pnacl 開發工具 (建議可以把檔案搜尋路徑設置過來.)</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="806">[root@www bin]# pwd<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/home/loda/nacl/native_client/toolchain/pnacl_linux_x86_64/glibc/bin</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www bin]# ls</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
driver.conf pnacl-as pnacl-dis pnacl-ld pnacl-nativeld pnacl-nop pnacl-readelf pydir wrapper-link-and-translate</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
findpython.sh pnacl-clang pnacl-driver pnacl-meta pnacl-nm pnacl-opt pnacl-strip readelf</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl-ar pnacl-clang++ pnacl-illegal pnacl-meta-unpack pnacl-nmf pnacl-ranlib pnacl-translate size</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www bin]#</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來讓我們以實際的例子驗證PNaCl執行檔,以如下的範例程式來說</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="806">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“loda PNaCl test!\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//write(1,”222″,4);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行如下命令進行編譯</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl-clang hello.c -o hello.pexe</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再把.pexe (BitCode)轉成.nexe(Native Code)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl-translate -arch x86-64 hello.pexe -o hello64.nexe</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就跟在 SDK中開發一樣, .nexe檔案的執行會需要透過有支援NaCl的瀏覽器執行環境,或是透過專屬的Run-Time工具,若我們直接在執行剛才編譯出來的執行檔,會看到如下的錯誤訊息</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">./hello64.nexe<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-bash: ./hello64.nexe: ld-nacl-x86-32.so.1: bad ELF interpreter: No such file or directory</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當然如果是希望透過瀏覽器執行,還是可以回到SDK環境中編譯把對應的Pepper版本與函式庫關係編譯到.nexe檔案格式中,但在Source Code Package中,有支援 run.py 可以不需額外透過瀏覽器,就能驗證程式開發的執行結果,如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="806">run.py hello64.nexe<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
********************************************************************************</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
hello64.nexe is X86-64 DYNAMIC</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
********************************************************************************</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/home/sena/nacl/native_client/scons-out/opt-linux-x86-64/staging/nacl_helper_bootstrap /home/sena/nacl/native_client/scons-out/opt-linux-x86-64/staging/sel_ldr -B /home/sena/nacl/native_client/scons-out/nacl_irt-x86-64/staging/irt.nexe -S -a — /home/sena/nacl/native_client/toolchain/linux_x86/x86_64-nacl/lib/runnable-ld.so –library-path /home/sena/nacl/native_client/toolchain/linux_x86/x86_64-nacl/lib /home/loda/LLVM/hello64.nexe</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
DEBUG MODE ENABLED (bypass acl)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[3877,3328583488:06:47:07.577028] BYPASSING ALL ACL CHECKS</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[3877,3328583488:06:47:07.591525] Native Client module will be loaded at base address 0x00007f7700000000</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[3877,3328370432:06:47:07.682474] NaClHostDescOpen: open returned -1, errno 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
loda PNaCl test!</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>檢視</strong><strong>pnacl-clang</strong><strong>所產生的</strong><strong>BitCode</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果要檢視所產生的.PEXE BitCode執行檔MetaData內容,可以透過pnacl-nmf 工具來操作,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl-nmf hello.pexe</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以產生如下的PNaCl BitCode MetaData內容,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">{<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“files”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“ld-nacl-x86-32.so.1″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“arm”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-arm/ld-nacl-x86-32.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“x86-32″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-x86-32/ld-nacl-x86-32.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“x86-64″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-x86-64/ld-nacl-x86-32.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“ld-nacl-x86-64.so.1″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“arm”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-arm/ld-nacl-x86-64.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“x86-32″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-x86-32/ld-nacl-x86-64.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“x86-64″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-x86-64/ld-nacl-x86-64.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“libc.so.c4697f70″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“portable”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“pnacl-translate”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“sha256″: “f4461ca0596a8eb5f51b1bedfe293a4490b03277f3e8530988a17a431964081b”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “libc.so.c4697f70″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“libgcc_s.so.1″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“arm”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-arm/libgcc_s.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“x86-32″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-x86-32/libgcc_s.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“x86-64″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-x86-64/libgcc_s.so.1″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“main.nexe”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“portable”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“pnacl-translate”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“sha256″: “16ff8742c8aa59ae918177b6bb1c9548f2479fa8033442d9089ca10c161c7d23″,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “hello.pexe”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“program”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“arm”: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-arm/runnable-ld.so”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“x86-32″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-x86-32/runnable-ld.so”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
},</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“x86-64″: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“url”: “lib-x86-64/runnable-ld.so”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再透過pnacl-dis反組譯 hello.pexe內容</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">; ModuleID = ‘hello.pexe’<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target datalayout = “e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target triple = “armv7-none-linux-gnueabi”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
deplibs = [ “ld-nacl-x86-32.so.1″, “libc.so.c4697f70″ ]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@_IO_stdin_used = internal constant i32 131073, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @__crtbegin_dummy to i8*)], section “llvm.metadata”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@__dso_handle = internal global i8* null, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@llvm.global_dtors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @__do_global_dtors_aux }]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@.str = private unnamed_addr constant [18 x i8] c”loda PNaCl test!\0A\00″, align 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@llvm.compiler.used = appending global [0 x i8*] zeroinitializer, section “llvm.metadata”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define void @_start(i32* %info) nounwind {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
entry:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%info.addr = alloca i32*, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%rtld_fini = alloca void ()*, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%argc = alloca i32, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%argv = alloca i8**, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32* %info, i32** %info.addr, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%0 = load i32** %info.addr, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%arrayidx = getelementptr inbounds i32* %0, i32 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%1 = load i32* %arrayidx, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%2 = inttoptr i32 %1 to void ()*</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store void ()* %2, void ()** %rtld_fini, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%3 = load i32** %info.addr, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%arrayidx1 = getelementptr inbounds i32* %3, i32 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%4 = load i32* %arrayidx1, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 %4, i32* %argc, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%5 = load i32** %info.addr, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%arrayidx2 = getelementptr inbounds i32* %5, i32 3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%6 = bitcast i32* %arrayidx2 to i8*</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%7 = bitcast i8* %6 to i8**</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i8** %7, i8*** %argv, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%8 = load i32* %argc, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%9 = load i8*** %argv, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%10 = load void ()** %rtld_fini, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%11 = call i8* @llvm.frameaddress(i32 0)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
call void @__libc_start_main(i32 (i32, i8**, i8**)* bitcast (i32 ()* @main to i32 (i32, i8**, i8**)*), i32 %8, i8** %9, i32 (i32, i8**, i8**)* @__libc_csu_init, void ()* @__libc_csu_fini, void ()* %10, i8* %11)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
br label %while.body</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
while.body: ; preds = %while.body, %entry</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%12 = load volatile i32* null, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
br label %while.body</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return: ; No predecessors!</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret void</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
declare void @__libc_start_main(i32 (i32, i8**, i8**)*, i32, i8**, i32 (i32, i8**, i8**)*, void ()*, void ()*, i8*)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
declare i32 @__libc_csu_init(i32, i8**, i8**)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
declare void @__libc_csu_fini()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
declare i8* @llvm.frameaddress(i32) nounwind readnone</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define void @_init() nounwind {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
entry:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret void</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define internal void @_fini() nounwind {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
entry:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret void</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define internal void @__crtbegin_dummy() nounwind {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
entry:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
call void @__do_global_dtors_aux()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i8* null, i8** @__dso_handle, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret void</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define internal void @__do_global_dtors_aux() nounwind {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
entry:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret void</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define internal i32 @main() nounwind {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
entry:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%retval = alloca i32, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 0, i32* %retval</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%call = call i32 (i8*, …)* @printf(i8* getelementptr inbounds ([18 x i8]* @.str, i32 0, i32 0))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret i32 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
declare i32 @printf(i8*, …)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
!NeededRecord_libc.so.c4697f70 = !{!0, !1}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
!OutputFormat = !{!2}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
!0 = metadata !{metadata !”__libc_start_main”}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
!1 = metadata !{metadata !”printf”}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
!2 = metadata !{metadata !”executable”}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>檢視</strong><strong>pnacl-translate NaCl</strong><strong>所產生的</strong><strong>Machine Code.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.PEXE執行檔可透過pnacl-translate轉成指定平台的Native Code執行檔,針對所產生的執行檔內容可透過pnacl-dis進行反組譯,操作如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pnacl-dis hello64.nexe</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
產生的反組譯內容如下所示 ()</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">………….<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0000000001000300 <main>:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000300: 55 push %rbp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000301: 48 89 e5 mov %rsp,%rbp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000304: 83 ec 10 sub $0x10,%esp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000307: 4a 8d 24 3c lea (%rsp,%r15,1),%rsp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100030b: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000312: bf 5c 02 00 11 mov $0x1100025c,%edi</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000317: 30 c0 xor %al,%al</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000319: 66 90 xchg %ax,%ax</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100031b: e8 e0 fd ff ff callq 1000100 <printf@plt+0xc0></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000320: 31 c0 xor %eax,%eax</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000322: 83 c4 10 add $0x10,%esp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000325: 4a 8d 24 3c lea (%rsp,%r15,1),%rsp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000329: 8b 2c 24 mov (%rsp),%ebp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100032c: 4a 8d 6c 3d 00 lea 0x0(%rbp,%r15,1),%rbp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000331: 83 c4 08 add $0x8,%esp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000334: 4a 8d 24 3c lea (%rsp,%r15,1),%rsp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000338: 59 pop %rcx</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000339: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000340: 83 e1 e0 and $0xffffffe0,%ecx</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000343: 4c 01 f9 add %r15,%rcx</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000346: ff e1 jmpq *%rcx</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000348: 66 66 66 66 66 66 2e data32 data32 data32 data32 data32 nopw %cs:0x0(%rax,%rax,1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100034f: 0f 1f 84 00 00 00 00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000356: 00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000357: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000358: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1000359: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100035a: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100035b: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100035c: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100035d: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100035e: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
100035f: 90 nop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Native Client能否普及仍待持續觀察,但這技術基於LLVM所帶來的創新思維,其實會讓深入探究其中的我們得到很多收穫,希望對於閱讀本文的各位也有一樣的獲益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
分享這段很棒的話語 <strong>‘</strong><strong>懷疑能把昨天的信仰摧毀,也能替明日的信仰開路</strong><strong>‘</strong><strong> by</strong><strong> </strong><strong>羅曼</strong><strong>‧</strong><strong>羅蘭</strong>, 每當新的技術誕生時,基於已經習知的知識背景,我們通常都會有先入為主的評價,當事後探究相關的技術細節,其實收穫最多的還是我們自己.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Google的Native Client SFI 技術,可以讓原本大家認為不安全的遠端瀏覽器下載Native Code的行為,有了一個全新的視野,Native Code不是原本認為的不受限制,只要有機會運作,就可以透過作業系統的System Call或利用組語機械碼去跳脫被限制呼叫的函式庫,而是會進入Native Client SFI機制所設計的Sandbox中,去阻擋各種非經許可的行為與機械碼的操作動作.更重要的是,不同於以往要透過User/Kernel Space以處理器特權等級作保護的機制,上述的SFI Sandbox都是在User Space這層級完成的.當然,這也代表了背後更多種無限的遐想與可能. <strong>(</strong><strong>玩破解的朋友們</strong><strong>,</strong><strong>這又多了一個好題目</strong><strong>!!!)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-29507321952812732052017-06-04T09:41:00.000-07:002017-06-04T09:41:14.650-07:00LLVM (Low Level Virtual Machine) 筆記<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
LLVM (Low Level Virtual Machine) 筆記</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>LLVM (Low Level Virtual Machine) </strong><strong>筆記</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
by loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
hlchou@mail2000.com.tw</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
很喜歡愛因斯坦所說的這段話,<strong><span style="text-decoration-line: underline;">“ </span></strong><strong><span style="text-decoration-line: underline;">在科學上</span></strong><strong><span style="text-decoration-line: underline;">,</span></strong><strong><span style="text-decoration-line: underline;">每一條道路都應該走一走</span></strong><strong><span style="text-decoration-line: underline;">. </span></strong><strong><span style="text-decoration-line: underline;">發現一條走不通的道路</span></strong><strong><span style="text-decoration-line: underline;">,</span></strong><strong><span style="text-decoration-line: underline;">就是對於科學的一大貢獻</span></strong><strong><span style="text-decoration-line: underline;">.</span></strong><strong><span style="text-decoration-line: underline;">科學史只寫某人某人取得成功</span></strong><strong><span style="text-decoration-line: underline;">,</span></strong><strong><span style="text-decoration-line: underline;">在成功者之前探索道路,發現</span></strong><strong><span style="text-decoration-line: underline;"> ‘</span></strong><strong><span style="text-decoration-line: underline;">此路不通</span></strong><strong><span style="text-decoration-line: underline;">‘ </span></strong><strong><span style="text-decoration-line: underline;">的失敗者統統不寫</span></strong><strong><span style="text-decoration-line: underline;">,</span></strong><strong><span style="text-decoration-line: underline;">這是很不公平的</span></strong><strong><span style="text-decoration-line: underline;">“</span></strong> . 第一次看到LLVM技術時,當時會心想跨平台的技術,不是已經有了JAVA 虛擬機搭配JIT(Just In Time)技術,或是微軟所推的.Net 也基於支援IL Assembly可以在跨平台的方案上得到滿不錯的效能. 又一個新出的LLVM跨平台技術,真的能帶來跟以往不同的好處嗎?</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在深入探究LLVM後,其實不論是在效能 (可以參考OpenBenchMark網站<a href="http://openbenchmarking.org/result/1204215-SU-LLVMCLANG23" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://openbenchmarking.org/result/1204215-SU-LLVMCLANG23</a> ),支援語法的廣泛性(包括 C/C++ 都可以直接編譯為LLVM BitCode),並且也支援指標,函式指標,Inline Assembly,對於一般應用程式的轉換上,成本可以大幅度的降低,所產生的BitCode除了可以透過LLI(LLVM Interpreter)執行外,也可直接轉譯為所在平台的機械碼.對多數的開發者而言,光是可以讓C/C++開發的成果只要由開發者編譯一次後,就可以擁有跨平台的特性,對許多產品開發上就已經很有誘因了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
實際下載LLVM編譯安裝前,可以先透過<a href="http://llvm.org/demo/index.cgi" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://llvm.org/demo/index.cgi</a> 由LLVM所提供的線上測試網站,在這可以嘗試把不同的C/C++語言透過LLVM線上轉譯為對應的BitCode Assembly語法,而這樣的IR中間語法,就可以再透過LLC轉譯為不同平台上的原生Assembly Code.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LLVM是由Vikram Adve與Chris Lattne在2000年開始進行開發,透過編譯器的技術,可支援把C/C++,Object-C,Fortran,Java ByteCode,Python,ActionScript以及其他程式語言編譯為LLVM BitCode Assembly. 基於這跨平台的BitCode Assembly就可以再轉譯為目標平台的可執行機械碼. 並在2004年於 Code Generation and Optimization (CGO’04)上發表了’LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation ‘ Paper (文章可在這取得http://llvm.org/pubs/2004-01-30-CGO-LLVM.pdf, 投影片網址<a href="http://llvm.org/pubs/2004-03-22-CGO-LLVM-Presentation.ppt" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://llvm.org/pubs/2004-03-22-CGO-LLVM-Presentation.ppt</a>),介紹當時LLVM LifeLong Optimization 概念,並在這Paper中提到LLVM幾個主要的特色</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, RISC Like的指令集.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 以SSA(Static Single-Assignment) 形式提供數目不設限的虛擬暫存器</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, 以Load/store 指令存取型態定義的指標(Typed-Pointer)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4, 基於SSA可明確資料在運作過程中的傳遞流程</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5, 提供跟語言無關的形態資訊</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6, 在exception的支援上提供 setjmp/longjmp實作的Exception機制,並提供 invoke指令可呼叫一個需要帶有Exception Handler的函式,與提供Unwind指令,能透過Stack Frame回推到上一個invoke指令位置.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在2005年時,Chris Lattner加入了Apple,也藉此讓LLVM成為Apple官方所支持的編譯器方案.在2005年以前,LLVM一直沒有在實際的商業化產品中導入,直到2005年後,才開始應用在相關商業產品中.有關LLVM 技術在Mac OS X 上的演進可以參考以下的連結 <a href="http://arstechnica.com/apple/reviews/2007/10/mac-os-x-10-5.ars/11#llvm" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://arstechnica.com/apple/reviews/2007/10/mac-os-x-10-5.ars/11#llvm</a> 與 <a href="http://arstechnica.com/apple/reviews/2009/08/mac-os-x-10-6.ars/9" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://arstechnica.com/apple/reviews/2009/08/mac-os-x-10-6.ars/9</a> .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在支援C/C++的部份,LLVM的前端可以為llvm-gcc或是Clang.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以llvm-gcc來說,這是基於GCC修改而來支援 C/Object-C 的LLVM C Front End編譯器工具,並因此而擁有許多GCC故有的能力,llvm-gcc可用來產生最終的執行檔案,或是LLVM BitCode 二進位檔案,或是LLVM Assembly原始碼.llvm-gcc在不加入任何參數下的預設行為跟原本的gcc一樣,會產生最終的可執行檔案,如果是加上 -emit-llvm與-c則是會產生LLVM BitCode的二進位檔案,若加上-emit-llvm與-S則是會產生LLVM的Assembly原始碼.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
既然已經有了llvm-gcc作為llvm的前端,又為何要有Clang呢? 可以參考這網頁上的訊息如下(<a href="http://linuxtoy.org/archives/llvm-and-clang.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://linuxtoy.org/archives/llvm-and-clang.html</a> )</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="803">Apple 使用 LLVM 在不支援全部 OpenGL 特性的 GPU (Intel 低端顯卡) 上生成代碼 (JIT),令程式仍然能夠正常運行。之後 LLVM 與 GCC 的集成過程引發了一些不快,GCC 系統龐大而笨重,而 Apple 大量使用的 Objective-C 在 GCC 中優先順序很低。此外 GCC 作為一個純粹的編譯系統,與 IDE 配合很差。加之許可證方面的要求,Apple 無法使用修改版的 GCC 而閉源。於是 Apple 決定從零開始寫 C family 的前端,也就是基於 LLVM 的 Clang 了。</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由此可知Clang(官方網站為<a href="http://clang.llvm.org/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://clang.llvm.org/</a>)將會是未來LLVM所主要搭配配的前端C/C++編譯器工作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LLVM本身主要是從處理器CPU的角度來進行虛擬化,也就是說讓各種語言所開發的應用程式都可以透過前端編譯器轉譯為LLVM虛擬處理器所能執行的BitCode,再將 BitCode轉譯為不同處理器平台的指令集<strong>(目前支援像是x86, ARM, MIPS,PowerPC,Sparc,XCore,Alpha…etc 處理器指令集)</strong>.也因此LLVM Compiler只需要專注再LLVM對BitCode轉譯為不同處理器平台機械碼優化的任務上即可,而不需在前端去面對各種不同程式語言的編譯與優化工作.LLVM的前端包括像是llvm-lua(http://code.google.com/p/llvm-lua/)可以把lua編譯為LLVM BitCode,或是llvm-java支援的class2llvm要把Java ByteCode轉譯為LLVM BitCode.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>LLVM 的跨平台支援演示.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下筆者以同樣是ARM平台來看,對同一個 BitCode Assembly,選擇要對Cortex-A9優化與要對ARM9優化選項後,所產生的組語有哪些差異</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]#</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# arm-none-linux-gnueabi-gcc -mcpu=arm9 sample_ar</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
m9.s -ldl -o sample_arm9</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>//</strong><strong>把</strong><strong>BitCode Assembly </strong><strong>針對</strong><strong>ARM </strong><strong>架構下的</strong><strong>Cortex-A9</strong><strong>處理器進行優化</strong><strong>,</strong><strong>並產生檔案到</strong><strong>sample_cortexa9.s</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#llc -O2 -march=arm -mcpu=cortex-a9 sample.bc -o sample_cortexa9.s</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>//</strong><strong>把</strong><strong>BitCode Assembly </strong><strong>針對</strong><strong>ARM </strong><strong>架構下的</strong><strong>ARM9</strong><strong>處理器進行優化</strong><strong>,</strong><strong>並產生檔案到</strong><strong>sample_arm9.s</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# llc -O2 -march=arm -mcpu=arm9 sample.bc -o sample_arm9.s</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>//</strong><strong>可再透過</strong><strong> Diff </strong><strong>比較針對</strong><strong>Cortex-A9</strong><strong>與</strong><strong>ARM9</strong><strong>優化後</strong><strong>,</strong><strong>兩者的差異</strong><strong> (</strong><strong>各位可以自行嘗試</strong><strong>,</strong><strong>筆者就不再此列舉內容</strong><strong>).</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# diff sample_corei7.s sample_atom.s</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
兩者最直接的差異就是在所產生的組語中,Cortex-A9會加入對 ‘.fpu neon’ 指令集的支援,而這是在不支援Neon指令集的ARM9處理器上所不會有的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後不免要把兩段BitCode實際編譯驗證,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# arm-none-linux-gnueabi-gcc -mcpu=cortex-a9 sample_cortexa9.s -ldl -o sample_cortexa9</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# arm-none-linux-gnueabi-gcc -mcpu=arm9 sample_arm9.s -ldl -o sample_arm9</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並且比較基於兩個不同處理器優化下,所產生最終執行檔的Size差異.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# ls -l sample_cortexa9</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x. 1 root root <strong>6877</strong> May 13 23:42 sample_cortexa9</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# ls -l sample_arm9</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x. 1 root root <strong>7201</strong> May 13 23:42 sample_arm9</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者把一段C Code (由於重點是在演示如何把C Code轉 BitCode,再透過BitCode轉成不同平台的Assembly,所以在此就不偏重C Code的內容了),先轉成BitCode,之後再編譯為跨不同處理器平台的Assembly原始碼與最終的執行檔案,藉此演示LLVM在支援不同平台優化技術上的能力.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">//</span></strong><strong><span style="text-decoration-line: underline;">透過</span></strong><strong><span style="text-decoration-line: underline;">clang </span></strong><strong><span style="text-decoration-line: underline;">把</span></strong><strong><span style="text-decoration-line: underline;">C</span></strong><strong><span style="text-decoration-line: underline;">程式碼編譯為</span></strong><strong><span style="text-decoration-line: underline;"> BitCode </span></strong><strong><span style="text-decoration-line: underline;">二進位檔案</span></strong><strong><span style="text-decoration-line: underline;">.</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# clang -O2 -emit-llvm sample.c -c -o sample.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# ls -l sample.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rw-r–r–. 1 root root 1956 May 12 10:28 sample.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">//</span></strong><strong><span style="text-decoration-line: underline;">把</span></strong><strong><span style="text-decoration-line: underline;">BitCode</span></strong><strong><span style="text-decoration-line: underline;">二進位檔案轉譯為</span></strong><strong><span style="text-decoration-line: underline;">x86-64</span></strong><strong><span style="text-decoration-line: underline;"> platform assembly code.</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# llc -O2 -mcpu=x86-64 sample.bc -o sample.s</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">//</span></strong><strong><span style="text-decoration-line: underline;">編譯轉譯後的</span></strong><strong><span style="text-decoration-line: underline;">assembly code 為 </span></strong><strong><span style="text-decoration-line: underline;">x86-64 </span></strong><strong><span style="text-decoration-line: underline;">native execution file.</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# gcc sample.s -o sample -ldl</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# ls -l sample</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x. 1 root root 8247 May 12 10:36 sample</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">//</span></strong><strong><span style="text-decoration-line: underline;">把</span></strong><strong><span style="text-decoration-line: underline;">BitCode</span></strong><strong><span style="text-decoration-line: underline;">二進位檔案轉譯為</span></strong><strong><span style="text-decoration-line: underline;"> </span></strong><strong><span style="text-decoration-line: underline;">ARM Cortext-A9 </span></strong><strong><span style="text-decoration-line: underline;">platform assembly code.</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# llc -O2 -march=arm -mcpu=cortex-a9 sample.bc -o</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
sample.s</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">//</span></strong><strong><span style="text-decoration-line: underline;">編譯轉譯後的</span></strong><strong><span style="text-decoration-line: underline;"> assembly code 為</span></strong><strong><span style="text-decoration-line: underline;"> ARM Cortext-A9</span></strong><strong><span style="text-decoration-line: underline;"> native execution file.</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# arm-none-linux-gnueabi-gcc -mcpu=cortex-a9 sample.s -ldl -o sample</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost reference_code]# ls -l sample</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x. 1 root root 6877 May 12 10:54 sample</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
藉由上述的演示,我們可以知道LLVM如何透過LLC(LLVM Compiler)把同一段BitCode轉譯為ARM或x86平台的組語,而所產生的Assembly Code可以再透過GCC編譯為所在平台的執行檔. 有關LLVM的編譯環境運作示意圖,可參考下圖的所示.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY_6xM1wB08XuSov3tXcpNJ71fl255uPyfslpQlM1obupEOEispRmywoCV6r9QoMSNwU4xXPI8N5X6NSBgand85hPvm_XYCxmuJvKfovica2eaUk4Kvem4kzHsps75pJNBHq7QGr5bE9c/s1600/image001%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="306" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY_6xM1wB08XuSov3tXcpNJ71fl255uPyfslpQlM1obupEOEispRmywoCV6r9QoMSNwU4xXPI8N5X6NSBgand85hPvm_XYCxmuJvKfovica2eaUk4Kvem4kzHsps75pJNBHq7QGr5bE9c/s1600/image001%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過LLVM前端把程式語言C/C++/Java/Fortran轉譯為BitCode Assembly,再藉由LLVM Compiler轉譯為不同平台差異的Assembly實作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Clang</strong><strong>的靜態分析語句引擎</strong><strong>(static analyzer)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Clang不只是LLVM前端的C/C++/Objective C/C++ 編譯器工具,還支援對軟體開發極有幫助的靜態程式碼分析工具,有關LLVM的Clang靜態語句分析(Clang Static Analyzer)工具的介紹可以參考網站<a href="http://clang-analyzer.llvm.org/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://clang-analyzer.llvm.org/</a> ,這工具可用以分析C與Objective-C所開發的應用程式(尚不支援 C++/Objective-C++).目前這工具是以Open Source的方式釋出,並成為Clang 計畫的一部分.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其實市場上原本已有一些靜態程式語言分析的商業化工具,像是Coverity 或是 Klocwork,可在開發階段針對所撰寫的C/C++,Java應用程式潛在的設計問題提供分析結果,讓開發者針對這些分析內容先行解決,如此可減少在RunTime QA 人員找出Bug後,還要再提交給研發人員覆現問題的往返時間成本.好的程式語言靜態分析工具可以提前找出可能是在哪一行發生記憶體拷貝的溢位,避免QA週期透過窮舉法去走過所有程式邏輯的路徑,涵蓋範圍的不足.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Clang基於LLVM環境編譯後,可以在llvm-3.0.src/tools/clang/tools/scan-build與llvm-3.0.src/tools/clang/tools/scan-view 這兩個路徑下取得scan-build與scan-view兩個Clang靜態分析工具編譯後的執行檔, scan-view 可用以檢視scan-build分析後產生到指定目錄中的結果報告.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,筆者以如下的程式碼來驗證scan-build靜態分析程式碼的能力,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="804">int main()<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char *p,*xp;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char vBuffer[128];</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int i;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
p=malloc(128);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
xp=(char *)malloc(222);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memset(p,256,0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
for(i=0;i<256;i++)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vBuffer[i]=0x00;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這段程式碼中,筆者把malloc回來的pointer不作NULL檢查就直接使用,並刻意memset超出所配置記憶體的空間,或是透過 for 迴圈故意寫出超過Array配置大小的範圍,如下所示為透過scan-build執行後,產生的錯誤訊息</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www LLVM]# ~/scan-build clang -O3 -emit-llvm test.c -c -I/usr/local/bin/../lib/clang/3.0/include/</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
test.c:9:2: warning: Value stored to ‘xp’ is never read</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
xp=(char *)malloc(222);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
^ ~~~~~~~~~~~~~~~~~~~</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 warning generated.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
scan-build: 1 bugs found.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
scan-build: Run ‘scan-view /tmp/scan-build-2012-05-20-6′ to examine bug reports.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後的報告是產生在 /tmp/scan-build-2012-05-20-6 目錄下,可以透過 scan-view工具進行檢視,如下指令.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@www LLVM]# ~/scan-view /tmp/scan-build-2012-05-20-7</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
檢視後的 Bug內容為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
File: test.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Location: line 11, column 2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Description: Value stored to ‘xp’ is never read</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以scan-build對這案例的分析結果來看,只有找出 xp 變數有被配置但沒有被使用的問題,其他更嚴重的溢位問題,並沒有被偵測出來. 以目前scan-build的分析能力,對商業化產品的開發,選擇Coverity 或klocwork這類功能比較完整的靜態程式碼分析工具,應該會是對軟體品質確保上有比較好的幫助才是.當然,若在一般性的檢查上,scan-build還是可以帶來一些幫助的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>SSA(Static Single-Assignment)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LLVM IR (Intermediary Representation)會以 SSA (Static Single Assignment) 的形式表述,在往LLVM Assembly進一步的探究前,SSA應該是最值得介紹的項目,也是目前LLVM Assembly在設計實作上的基礎思維. 簡要來說,SSA的技術是由Wegman,Zadeck,Alpern,與Rosen在1988來開始發展,目前已經應用在GCC 4.0,IBM或Sun的Java JIT Compiler. SSA主要的概念為每個變數會被限制只能被給值一次的中間形式(IR),也就是說在轉成IR型態後,原本認為的變數,會在每次內容被改變時,就會重新把結果給值到一個新的變數中,例如變數X在運算過程中內容被改變了5次,就會因此而產生五個與最終給值有關的中間形式靜態單一分配形式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每個描述式結果都會對應到一個全新的變數 (也就是說假設所在的環境中,全新變數宣告的總數也是沒有上限的.)</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">原本的描述式</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="406">轉成SSA後</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">x=a + b<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
y=b + x</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x=a + 21</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x=c * x</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
y=x + b</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="406">x1 = a + b<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
y1 = b + x1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x2 = a + 21</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x3 = c * x2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
y2 = x3 + b</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
經過SSA 的Dead Code Elimination後,編譯器就可以識別出其實x1與y1是沒有必要存在而可以加以優化消除的,簡化後的結果如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="329">x2 = a + 21<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x3 = c * x2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
y2 = x3 + b</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>LLVM </strong><strong>跟</strong><strong>Dalvik </strong><strong>執行環境的比較</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從目前的趨勢上,LLVM很有機會在Android執行環境扮演一定程度的角色,相對於Dalvik Java 的執行環境,LLVM可以提供更貼近於平台Native應用程式的執行效能. 在跨平台的能力上,Dalvik可以選擇透過 Portable Interpreter (in C), Fast Interpreter (in Assembly)或基於Just-In Time Compiler編譯技術,在支援Neon指令集的平台上,JIT目前也能透過Neon指令產生優化後的結果.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而同樣的優勢,到了LLVM後又更進一步的改變,例如LLVM的IR(Intermediate Representation)是給LLVM直譯器/編譯器看的IR,相對於Java的ByteCode是一個被編譯後的結果,而JIT所做的優化則是根據每個Java ByteCode指令集操作改用原生指令實作所進行的優化(例如:把Dalvik move-wide指令用ARMv7 NEON指令實現,以進行加速),也就是說當從Java Code轉成ByteCode時,實際上有關應用程式流程的優化動作已經被進行過,所產生的ByteCode是適合直接上到Java處理器/虛擬機上執行的結果.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但,在LLVM透過Front-End所產生的結果則是一個還需要經過編譯的中間結果,並且是以SSA (Static Single Assignment) 編譯結果表述的內容,也就是說當BitCode要執行時,還需要透過LLI (LLVM Interpreter)或LLC (LLVM Compiler)來進行直譯或是編譯為目標平台原始碼的過程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也因此,相較於Java JIT技術的結果,LLVM可以提供更接近於原生應用程式的效能,能根據基於LLVM IR所表述的SSA BitCode結果,重新優化編譯為目標平台的機械碼,相較於Java ByteCode的作法,是基於已經編譯好的ByteCode結果,把每個ByteCode指令改用以平台上的機械碼實現,LLVM能帶來的優化程度與結果是相對較佳的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡單來說,兩者最大的差異有</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1, </strong><strong>從產生的執行碼來看</strong><strong>: </strong>BitCode可以被LLVM編譯為原生碼,而且運作過程中直接呼叫Native函式庫,也可以直接被處理器執行.反觀Dalvik ByteCode,必須要基於Dalvik 虛擬機執行,就算是基於Dalvik JIT Compiler的技術,也只有部分的Dalvik ByteCode Trace-Run區塊可以被編譯為原生的機械碼,並不像是LLVM技術所產生的原生碼,是可以100%運作在原生碼執行的環境中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,</strong><strong>從編譯後的原生碼重用性來看</strong><strong>:</strong> LLVM可以把BitCode整個優化為原生碼,目前Dalvik ByteCode只支援執行時期階段的ByteCode JIT Compiler,一旦Dalvik應用程式結束,所有JIT編譯後的結果就消失了,必須要等下一次該Dalvik應用程式重新被載入執行,再根據每一個ByteCode Trace-Run區塊的Counter重新去決定哪些區塊要被編譯為Native Code.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3,</strong><strong>從執行時期負荷來看 </strong><strong>:</strong>LLVM Compiler後的結果,能以原生應用程式的方式執行,但Dalvik JIT會跟去Trace-Run Counter結果統計出熱區重新編譯,取得優化後的效能,對處理器的Run-Time負荷來說,LLVM顯然可以帶來更好的改善. 若Dalvik Application把主要的運算都放到JNI .so動態函式庫中,試圖改善Run-Time的效能問題,但卻會因為.so是有平台相依性的,而必須要針對所有的平台都提供一份專屬的.so.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>4,</strong><strong>從記憶體需求的角度來看</strong><strong>:</strong>統計編譯後的結果,Clang把C/C++程式碼編譯為 LLVM IR之後透過LLVM Compiler轉譯為目標平台Assembly後所產生的執行檔大小,甚至可以比起直接透過GCC編譯的結果更佳,而Dalvik應用程式,在經過JIT後大小會膨脹 (一般來說為 4-8倍),並且相關的JAR Framework載入後,若也有相關的熱區,也會需要經由JIT技術來加以即時編譯優化,並儲存到JIT Cache中,相較於LLVM技術則無需有這段額外的記憶體成本在.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>5,</strong><strong>從儲存空間的需求來看</strong><strong>: </strong>一般的Dalvik Application APK需要有兩份儲存空間一個是DEX所在的.apk,一個是ODEX 儲存在dalvik-cache中.而LLVM Application並無這樣的必要.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>6,</strong><strong>從系統安全性的角度來看</strong><strong>:</strong>LLVM支援指標/Inline Assembly,這是在Java世界中所不允許的,也因為支援指標,甚至是函式指標,可讓LLVM在效能的提升上得到很好的改善,但卻也隱藏了潛在的安全問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,為一個Dalvik應用程式在執行時相對於Dalvik 虛擬機與.so動態函式庫的示意圖,我們可以看到 Dalvik應用程式主要還是基於 ByteCode Based的JAR Framework,或是可直接透過JNI介面去呼叫外部的.so動態函式庫,以便得到接近原生碼的執行效能.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_BZ6rs3kD2SjcV3lzy8FUsvDPYxgEmeTTQKBQIE9Bmr2eO2TS_88G93OORSu_yfT8cGmFNQNTdrDsE_GIUoT02uxz11XOFAFeGs_NCckt6NDDzB7RjXrzH2elN4kDqbmcEya5pYSWyv0/s1600/image002%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="619" data-original-width="753" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_BZ6rs3kD2SjcV3lzy8FUsvDPYxgEmeTTQKBQIE9Bmr2eO2TS_88G93OORSu_yfT8cGmFNQNTdrDsE_GIUoT02uxz11XOFAFeGs_NCckt6NDDzB7RjXrzH2elN4kDqbmcEya5pYSWyv0/s1600/image002%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">接下來,可以參考下圖為透過LLVM Interpreter 執行BitCode應用程式的示意圖,可以看到除了LLVM BitCode應用程式以外,其他外部函式的呼叫都會直接對應到原生的.so動態函式庫.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQFbhvDZ-s4QcuV6BF9tx6wWR_P9sDaMqIaTmzuCiiEQHfkknUiP05eUqjIb9qTcGvgYpv88iwsZpxbmjrNoGlRvfhbUgEwW1xgCEAhTPkUGEDyYGmAYBREsoFDul9yXR3PyC-xj4Sz94/s1600/image003%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="422" data-original-width="620" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQFbhvDZ-s4QcuV6BF9tx6wWR_P9sDaMqIaTmzuCiiEQHfkknUiP05eUqjIb9qTcGvgYpv88iwsZpxbmjrNoGlRvfhbUgEwW1xgCEAhTPkUGEDyYGmAYBREsoFDul9yXR3PyC-xj4Sz94/s1600/image003%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
到這段落,各位以該對於Dalvik/LLVM應用程式在Run-Time上的差異有所了解了,接下來筆者將介紹另一個LLVM延伸的重要應用Native Client(Nacl) 與 Portable Native Client (PnaCl).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Native Client(Nacl) and Portable Native Client (PNaCl)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Google是在約2008開始進行Native Client的開發工作,並在2009年初舉辦Google Native Client Security/Hacking比賽 ,可參考網頁:http://www.zdnet.com/blog/google/hack-googles-native-client-and-get-8192/1295,比賽結果可以在這看到https://developers.google.com/native-client/community/security-contest/,並在Google 瀏覽器Chrome 10之後加入對Native Client的支援.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Native Client是類似微軟早期在Internet Explorer上支援的 ActiveX OCX元件的想法,讓網頁應用程式可以用處理器原生碼在支援這技術的瀏覽器直接執行. 參考Native Client網頁說明,簡單來說目標就是 <strong>“seamlessly execute native compiled code inside the browser”</strong>,也就是可以 “在瀏覽器上無縫執行編譯後的機械碼 “. 目前Native Client編譯後的NaCl Executable (*.NEXE) 檔案格式,會根據目標平台編譯,例如筆者所使用的Windows 7 64bits電腦執行環境,所編譯出的NEXE檔案中的機械碼就會是是用於x86_64環境執行的程式碼,也就是說在開發Native Client時,所產生的NEXE檔案是沒有辦法直接跨到其它平台執行的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於Native Client SDK,一個Native Client技術的NEXE執行檔案可以透過如下i686-nacl-gcc 編譯指令編譯出來,如果透過i686-nacl-objdump 去觀察編譯後的結果,可以注意到每個函式的起點都必須是32bytes Alignment的記憶體位址.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>i686-nacl-gcc -o hello_loda_x86_32.nexe hello_loda.c -m32 -O0 -g -pthread -O0 -g -Wno-long-long -Wall -lppapi -ldl</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考網頁https://developers.google.com/native-client/overview,Native Client,Native Client支援Software Fault Isolation (SFI),用以檢查所下載機械碼安全性的SandBox大約會讓帶來5%的Overhead.但由於Native Client是以機械碼的方式載入到使用者瀏覽器中執行,因此包括處理器的暫存器與支援inline assembly的寫法,都會比起透過Java Applet+Just-In-Time Compiler 或是透過Flash Action Script在瀏覽器中支援應用程式的方式來的更有安全性的疑慮. 舉個例子來說,這表示如果Native Client的Security SandBox如果沒有防守好的話,就有機會讓一個你在瀏覽網頁過程中所執行的Web Application讀取到你電腦上的檔案資料,或是有機會對將其他的惡意代碼寫入到你的電腦中,讓使用者電腦在不預期的狀況下,被第三方的應用程式給植入.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於Native Client本身機制是產生出x86 32bits 與 64bits的機械碼,目前也不支援x86以外的平台,因此Google也在2010年時進行新的PNacl (發音為Pinnacle)技術開發,各位可以參考Google的’PNaCl Portable Native Client Executables’文件,如果要讓使用者根據不同平台的差異(X86-32/64 bits,Java,ARM,MIPS,PowerPC….etc)自行編譯出相關的執行檔案進行驗證無誤後發佈產品,這背後會有相當的難度,也因此,Google基於LLVM BitCode的特性開發了PNacl的技術,可參考筆者從文件’PNaCl Portable Native Client Executables’所截出的下圖,PNaCl的想法是開發者產出的是BitCode的檔案格式 (非原本Native Client的X86 32/64 bits ISA指令集),在網頁瀏覽的過程中,由使用者下載包含該BitCode內容的PNaCl檔案格式,透過LLC (LLVM Compiler)技術,動態的在目標平台上把BitCode轉譯為目標平台上的可執行機械碼,隨後成為一個NaCl執行檔案.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdzRAF1AWSLuEs6DyN76DLfxcb73Mzu_pfUpQ4X0zDTmfr4g-dmHJKgsb4-QLaLW9-PRoYVhF6Rg3-SDgfuZYMNYKm6smbDN2Q5cm1wvA76GzXDWqxc3nN8u8-G8olfGTnvtEdueNHSgo/s1600/image004%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="445" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdzRAF1AWSLuEs6DyN76DLfxcb73Mzu_pfUpQ4X0zDTmfr4g-dmHJKgsb4-QLaLW9-PRoYVhF6Rg3-SDgfuZYMNYKm6smbDN2Q5cm1wvA76GzXDWqxc3nN8u8-G8olfGTnvtEdueNHSgo/s1600/image004%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於這樣的設計,等於可以延續Native Client計有的基礎,又可以讓產生機械碼的動作不是在開發者開發階段就要去面對不同平台差異而去產生,開發者所需面對的只有LLVM的BitCode,並且只要基於BitCode的環境驗證無誤下,就可以透過目前LLVM的優勢把BitCode重新編譯為目標平台上的機械碼,如此就可以延續目前Native Client的基礎,但又可以真正的達到跨所有處理器平台的目的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
下圖同樣為Google的’PNaCl Portable Native Client Executables’文件中的截圖,可以看到PNaCl的概念上,是透過LLVM BitCode達成跨平台的目的,在基於NaCl SandBox技術確保Native Client 執行環境的安全性.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-__OhUugxMsbMSauyNFaSFvRP0c7okJ_J_EBiSfUfIanKfegA_Q-ZOl-dy9nVajQLpu8uvYbhrcXraosaMiwqBfcmhoKPs7HXLdgJMrxWMp8-mGQJ0uNxeyyrDe0rJxQULtdMItRmpQI/s1600/image005%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="553" data-original-width="783" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-__OhUugxMsbMSauyNFaSFvRP0c7okJ_J_EBiSfUfIanKfegA_Q-ZOl-dy9nVajQLpu8uvYbhrcXraosaMiwqBfcmhoKPs7HXLdgJMrxWMp8-mGQJ0uNxeyyrDe0rJxQULtdMItRmpQI/s1600/image005%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Portable Native Client官方網頁為<a href="http://www.chromium.org/nativeclient/pnacl/building-and-testing-portable-native-client" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.chromium.org/nativeclient/pnacl/building-and-testing-portable-native-client</a> , 基於PNaCl所產生的執行檔為PEXE (原本的Native Client為NEXE),使用LLVM編譯器的好處是,開發者可以用C/C++語言開發,然後基於LLVM可以讓NACL應用程式在Browser上運作時,效率接近直接用C/C++語言針對該平台編譯的結果,而且最重要的是又可以用同一套LLVM產生中間碼(IL)的結果相容於所有的處理器平台.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Native Client定義跟Web Browser (例如目前Google的Chromium) 之間的介面為Pepper,可用以讓Native Client據此實作成為Browser Plug-in. Pepper介面是從Mozilla的NPAPI而來,新版的Native Client Pepper v2介面則重新在NPAPI基礎增加新的API介面.有關Pepper API的說明可以參考網頁<a href="http://code.google.com/p/ppapi/wiki/Concepts" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://code.google.com/p/ppapi/wiki/Concepts</a> .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考目前Native Client的文件,基於安全性的考量Native Client在施行上會有以下的限制存在</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,不支持Hardware Exception.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, 不支持產生新的Process/Subprocess</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,不支持Raw TCP/UDP Sockets (會額外提供WebSockets 供TCP與UDP Peer-to-Perr Connection.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,不支持同步(Synchronous) Blocking I/O</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,不支持對可使用記憶體的查詢</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,可以使用Inline Assembly,但必需要通過Native Client Validator (ncval) 工具的查核</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,跟Native Client所 Plug-in進Browser介面的Pepper API呼叫必須從應用的Main Thread而來.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Google Native Client的相關資訊可以參考</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">Google Code Project</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">http://code.google.com/p/nativeclient/</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">Native Client SDK</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">https://developers.google.com/native-client/?hl=zh-TW</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">Download Native Client SDK</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">https://developers.google.com/native-client/sdk/download?hl=zh-TW</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">Test Run</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">https://developers.google.com/native-client/devguide/devcycle/running?hl=zh-TW</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">Distribute</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">https://developers.google.com/native-client/devguide/distributing?hl=zh-TW</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">Getting Start</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403"><a href="https://developers.google.com/chrome/web-store/docs/get_started_simple?hl=zh-TW#step4" style="color: #666666; font-weight: bold; text-decoration-line: none;">https://developers.google.com/chrome/web-store/docs/get_started_simple?hl=zh-TW#step4</a></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前為止我們知道LLVM技術將有機會更廣泛的應用到瀏覽器技術上,與我們生活更緊密的結合,既然知道到LLVM本身的認識是可以把BitCode透過LLI (LLVM Interpreter)以直譯方式執行,或是透過LLC (LLVM Compiler)轉譯為不同平台上的機械碼,相對的把C/C++這些主要開發語言轉譯為BitCode的前端編譯器就變得很重要了,下一段落就讓我們實際操練Clang與LLVM的執行環境.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>編譯第一個</strong><strong>LLVM</strong><strong>程式</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來讓我們嘗試編譯一個基於BitCode檔案格式的LLVM程式,首先如下範例程式</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="811">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“LLVM Test\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過clang -S -emit-llvm test.c -o test.llvm 進行編譯,可以產生 LLVM的Assembly Code,如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="811">; ModuleID = ‘test.c’<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target datalayout = “e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target triple = “x86_64-unknown-linux-gnu”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@gCount = global i32 0, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@.str = private unnamed_addr constant [11 x i8] c”LLVM Test\0A\00″, align 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define i32 @main() nounwind uwtable {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%1 = alloca i32, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%i = alloca i32, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 0, i32* %1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%2 = call i32 (i8*, …)* @printf(i8* getelementptr inbounds ([11 x i8]* @.str, i32 0, i32 0))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret i32 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
declare i32 @printf(i8*, …)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關LLVM Assembly Code格式的介紹可以參考<a href="http://llvm.org/docs/LangRef.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://llvm.org/docs/LangRef.html</a> .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以透過 clang -c -emit-llvm test.c -o test.bc,產生LLVM BitCode格式的檔案,並且可以透過lli執行所產生的 BitCode檔案,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# lli test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LLVM Test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來可以透過llvm-dis 反組譯 test.bc為test.ll</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# llvm-dis test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為test.ll內容</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="803">[root@localhost test]# more test.ll<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
; ModuleID = ‘test.bc’</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target datalayout = “e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128″</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target triple = “x86_64-unknown-linux-gnu”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@gCount = global i32 0, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@.str = private unnamed_addr constant [11 x i8] c”LLVM Test\0A\00″, align 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define i32 @main() nounwind uwtable {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%1 = alloca i32, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%i = alloca i32, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 0, i32* %1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%2 = call i32 (i8*, …)* @printf(i8* getelementptr inbounds ([11 x i8]* @.str, i32 0, i32 0))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret i32 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
declare i32 @printf(i8*, …)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並可透過llvm-as test.ll 重新把test.ll編譯為test.bc.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# llvm-as test.ll</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# ls -l test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rw-r–r–. 1 root root 656 Apr 10 22:49 test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# date</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tue Apr 10 22:49:22 CST 2012</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]#</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來讓我們以LLVM 把兩個BitCode檔案進行Link,以驗證LLVM的運作行為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先 testA.c如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="810">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
long funcB();</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int X=funcB();</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“X:%xh\n”,X);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而 testB.c如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="810">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
long funcB()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0x9999999;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
先把 testA.c與testB個別編譯為 testA.bc與testB.bc 兩個BitCode檔案格式,再透過llvm-link把這兩個BitCode檔案Link成一個test.bc檔案,再透過lli 執行該BitCode test.bc檔案.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# clang -c -emit-llvm testA.c -o testA.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# clang -c -emit-llvm testB.c -o testB.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# llvm-link testA.bc testB.bc -o test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# lli test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
X:9999999h</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]#</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,也可以先把 testB.bc先Archive 成一個libTestB.a 的靜態連結函式庫,並透過llvm-nm檢視該函式數所提供的Symbol,最後再透過llvm-ld把 testA.nc跟靜態函式庫libTestB.a 進行連結成Native執行檔案的動作,最後就可以透過 ./test驗證最終執行結果是否符合預期.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# llvm-ar rucs libTestB.a testB.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# llvm-nm libTestB.a</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
T funcB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# llvm-ld testA.bc -o test -lTestB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# date</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tue Apr 10 22:57:42 CST 2012</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# ls -l test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x. 1 root root 66 Apr 10 22:57 test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# ./test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
X:9999999h <strong>=>符合預期.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]#</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在實際操練LLVM有關的工具指令後,接下來就是介紹LLVM 反組譯與BitCode檔案格式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>LLVM Assembly Language 與 </strong><strong>程式碼反組譯</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關LLVM Assembly Language的支援列表筆者另外整理在<a href="http://loda.hala01.com/llvm-assembly-language/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://loda.hala01.com/llvm-assembly-language/</a> ,供參考.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LLVM的Identifiers可以區分為Global全域開頭為’@’的Identifiers(包括函式與全域變數)與Local區域開頭為’%’的Identifiers,如前面的例子,所有的變數會以其命名作為字串但加上@或%表示其為全域變數(例如:@gX)或是區域變數(例如:%Y).參考’ LLVM Language Reference Manual’文件可接受的字元包括 ‘ [%@][a-zA-Z$._][a-zA-Z$._0-9]*’,如果有遇到不在這範圍內的字元,就會透過16進位的方式儲存,同樣以前述的例子來說,函式main的字串會以 ‘ main:%d\0A\00’方式儲存,長度為9bytes,其中\0A代表0x0A的16進位字元,而\00則代表0x00的字串結尾字元.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
沒有在程式設計階段被命名的變數,就會以上述像是%11, @22,%33或@44這類數字形式方式來命名.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
常數Constants的部份,筆者說明列舉如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183">常數型態</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183">Boolean</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">i1(a single-bit integer),<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會以’true’ 與 ‘false’ 代表長度為1bit的整數值</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183">Integer</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">通常為i32 (a 32-bit integer),可以用來表示負值,長度可為i1(1bit), i2(2bits), i3(3bits), … i8 (8bits), … i16 (16bits), … i32 (32bits), … i64 (64bits), …</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183">Floating point</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">通常為half(16-bit floating point value),float(32-bit floating point value)或double(64-bit floating point value),表示的方式可以為10或16進位浮點數(double 0x432ff973cafa8000),或指數符號(例如1.23456e+2)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183">Null pointer</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">為Pointer Type,會以 ‘null’ 字串表示Null Pointer Constant</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183"><strong>Structure</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">結構常數的組成會以{}括號來定義前後範圍,並以逗號’,’分隔前後的組成變數,每個組成變數都會包括它的形態(i32,float,i32*,double…etc),例如像是”{ i32 4, float 17.0, i32* @G }”,其中’i32* @G ‘表示這個變數儲存的是全域變數 ‘@G’ 的位址,可用於透過存取這個結構時,再藉由這個變數去存取全域變數’@G’.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183"><strong>Array</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">Array的組成會以[]方括號來定義前後範圍,並以逗號’,’分隔前後的變數值,每個變數都會包括它的形態,例如像是 “[ i32 42, i32 11, i32 74 ]”,Array中常數的型態與變數個數,都需要跟原本所宣告的形態一致,例如像是'[11 x i32]'(Array of 11 32-bit integer values)或'[4 x i8]’ (Array of 4 8-bit integer values).</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183">Vector</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">Vector的組成會以<>的小於/大於括號來定義前後範圍, 並以逗號’,’分隔前後的變數值,每個變數都會包括它的形態,例如像是 “< i32 42, i32 11, i32 74, i32 100 >”,Vector中常數的型態與變數個數,都需要跟原本所宣告的形態一致</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183"><strong>Zero initialization</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">字串“zeroinitializer’ 可用以進行初始化值為零的任何型態(Type),通常應用在像是大型的Array,可以讓相關的變數初始化為Zero.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="183"><strong>Metadata node</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="625">A metadata node is a structure-like constant with?metadata type. For example: “metadata !{ i32 0, metadata !”test” }”. Unlike other constants that are meant to be interpreted as part of the instruction stream, metadata is a place to attach additional information such as debug info.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在變數的部分,當在程式設計階段,給定一個全域變數常數值時,這個全域變數所包含的常數內容,就可以在執行時期的任意時間點被參考與使用,可參考如下兩個全域32 bits Integer變數,與一個全域大小為2*32bits Array的宣告,初值的給予.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@X = global i32 17</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@Y = global i32 42</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@Z = global [2 x i32*] [ i32* @X, i32* @Y ]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在初值的部份,執行可以設定初值為’Undefined Values’,定義為Undefined Values的變數就表示應用程式並不在意該值的初始化內容,指定的方式可以為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
i32 undef</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 undef, i32 *%1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者以如下程式碼作為例子,來進行編譯後的LLVM BitCode檔案格式解析與對反組譯BitCode Assembly的比對.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="809">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long long gW=10;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
long gX;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned int gY=30;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
short gZ;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned char gC=50;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
short FuncBC(int vA)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y=((gC+gW+gX)*vA)+40;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y*=gX+20;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“FuncBC:%d\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static unsigned long FuncA(int vA,int vB)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
gX=vA+vB;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
gZ=gC+vB;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y=gC*(gX+gY+gZ)+10;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y*=gX+30;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
gZ=FuncBC(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“FuncA:%d\n”,gZ);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Y=99;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int i;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
for(i=0;i<99999;i++)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y++;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y=FuncA(Y,30);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“main:%d\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
編譯這段範例程式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
clang -c -emit-llvm test.c -o test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
進行反組譯</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
llvm-dis test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
進行BitCode檔案格式分析.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
llvm-bcanalyzer -dump test.bc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先從反組譯的程式碼來看,5個全域變數轉成BitCode後的內容如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">C中的變數宣告</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">BitCode產生的變數宣告</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">unsigned long long gW=10;</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">@gW = global i64 10, align 8</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">long gX;</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">@gX = common global i64 0, align 8</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">unsigned int gY=30;</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">@gY = global i32 30, align 4</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">short gZ;</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">@gZ = common global i16 0, align 2</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">unsigned char gC=50;</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">@gC = global i8 50, align 1</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以知道,long長度為 64bits,int長度為32bits,short長度為16bits而char長度為8bits.預設的變數為unsigned,若屬於signed的變數則會加上common.沒有給予初值的全域變數預設值為0.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,定義為static function的話會加上internal,外部函式會以declare方式宣告原型,內部函式的定義會透過define,每個函式的函式參數會以型別跟參數名稱依序定義在函式參數中.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">C中的函式宣告</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">BitCode產生的函式宣告</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">使用到外部呼叫printf 函式</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">declare i32 @printf(i8*, …)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">int main()</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">define i32 @main() nounwind uwtable</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">static unsigned long FuncA(int vA,int vB)</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">define internal i64 @FuncA(i32 %vA, i32 %vB) nounwind uwtable</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">short FuncBC(int vA)</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="408">define signext i16 @FuncBC(i32 %vA) nounwind uwtable</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而以函式名稱的宣告來看,在這範例中筆者有宣告如下三個函式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
short FuncBC(int vA)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static unsigned long FuncA(int vA,int vB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在編譯為 BitCode後,會依據這三個函式名稱的長度,例如main為 ‘ main:%d\0A\00′,長度為9. (main:%d 長度為 7 bytes, 加上 0x0A 跟 0x00 各 1byte就為 9 bytes.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@.str = private unnamed_addr constant [11 x i8] c”FuncBC:%d\0A\00″, align 1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@.str2 = private unnamed_addr constant [10 x i8] c”FuncA:%d\0A\00″, align 1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@.str1 = private unnamed_addr constant [9 x i8] c”main:%d\0A\00″, align 1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
提到LLVM Assembly,最值得參閱的文件為’ LLVM Language Reference Manual’,可參考的網頁位置在<a href="http://llvm.org/docs/LangRef.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://llvm.org/docs/LangRef.html</a> . LLVM Assembly目標在於成為一個 ‘Universal IR’,也就是可以滿足讓各種程式語言對應到的Assembly Code,不管開發者使用的是C/C++,Java,Python …等等,都可以透過LLVM的Front-End前端編譯器(例如 Clang)把這些開發的Source Code轉譯為IR Assembly,以便讓LLVM本身可以把所產生的IR程式碼重新編譯到最後所要執行的處理器平台上(像是 x86,ARM或MIPS..等).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,可以先從C與編譯後的BitCode反組譯內容來做為這段落的起點</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">C Code</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="407">BitCode反組譯的結果</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">short FuncBC(int vA)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y=((gC+gW+gX)*vA)+40;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y*=gX+20;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“FuncBC:%d\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="407">define signext i16 @FuncBC(i32 %vA) nounwind uwtable {<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%1 = alloca i32, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%Y = alloca i32, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 %vA, i32* %1, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%2 = load i8* @gC, align 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%3 = zext i8 %2 to i64</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%4 = load i64* @gW, align 8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%5 = add i64 %3, %4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%6 = load i64* @gX, align 8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%7 = add i64 %5, %6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%8 = load i32* %1, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%9 = sext i32 %8 to i64</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%10 = mul i64 %7, %9</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%11 = add i64 %10, 40</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%12 = trunc i64 %11 to i32</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 %12, i32* %Y, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%13 = load i64* @gX, align 8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%14 = add nsw i64 %13, 20</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%15 = load i32* %Y, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%16 = sext i32 %15 to i64</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%17 = mul nsw i64 %16, %14</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%18 = trunc i64 %17 to i32</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 %18, i32* %Y, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%19 = load i32* %Y, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%20 = call i32 (i8*, …)* @printf(i8* getelementptr inbounds ([11 x i8]* @.str, i32 0, i32 0), i32 %19)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%21 = load i32* %Y, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%22 = trunc i32 %21 to i16</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret i16 %22</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於SSA的概念,我們可以把C語言與BitCode程式碼對應如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="280">C Code</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="529">BitCode反組譯的結果</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="280">short FuncBC(int vA)</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="529">define signext i16 @FuncBC(i32 %vA) nounwind uwtable</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="280">int Y;</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="529">%1 = alloca i32, align 4<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//宣告 int Y</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%Y = alloca i32, align 4</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="280">Y=((gC+gW+gX)*vA)+40</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="529">//把 vA儲存到 %1<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 %vA, i32* %1, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//把 gC 儲存到 %2,並Extend為i64到%3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%2 = load i8* @gC, align 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%3 = zext i8 %2 to i64</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//把gW儲存到%4,讓%3加%4等於%5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%4 = load i64* @gW, align 8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%5 = add i64 %3, %4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//把gX儲存到 %6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%6 = load i64* @gX, align 8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//讓%6加%5等於%7</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%7 = add i64 %5, %6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//讓vA等於%1儲存到%8,並Extend為i64到%9</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%8 = load i32* %1, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%9 = sext i32 %8 to i64</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//讓%7與%9相乘把結果儲存到%10</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%10 = mul i64 %7, %9</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//讓%10結果加上40,並儲存到%11</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%11 = add i64 %10, 40</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Truncate %11到i32 bits,結果為%12</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%12 = trunc i64 %11 to i32</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//最後把結果((gC+gW+gX)*vA)+40儲存在 Y</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 %12, i32* %Y, align 4</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="280">Y*=gX+20;</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="529">//把 gX放到 %13<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%13 = load i64* @gX, align 8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//對 %13 加上20 然後儲存到%14</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%14 = add nsw i64 %13, 20</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//把 Y值儲存到%15</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%15 = load i32* %Y, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Extend %15到i64後 儲存到%16</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%16 = sext i32 %15 to i64</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//把%14跟%16相乘後 儲存到%17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%17 = mul nsw i64 %16, %14</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//把%17的相乘結果Truncate 後除存在%18</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%18 = trunc i64 %17 to i32</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//把%18儲存在 Y值</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
store i32 %18, i32* %Y, align 4</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="280">printf(“FuncBC:%d\n”,Y);</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="529">//把Y值儲存在%19<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%19 = load i32* %Y, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//呼叫外部函式 printf,並把 %19 當做 %d 的參數</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%20 = call i32 (i8*, …)* @printf(i8* getelementptr inbounds ([11 x i8]* @.str, i32 0, i32 0), i32 %19)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="280">return Y;</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="529">//把最後Y值結果Truncate 後除存在%22<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%21 = load i32* %Y, align 4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
%22 = trunc i32 %21 to i16</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//以%22作為最後Y值的返回結果</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret i16 %22</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>原始資料編碼</strong><strong> (Encoding Primitive)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BitStream的封裝會以最少的Bit數來呈現每個有意義的Byte數值,BitStream會把這些原始資料數值以Unsigned Integer 數值的方式編碼,主要的編碼方式包括固定長度整數 (Fixed Width Integer),可變長度整數 (Variable Width Integer),字元編碼(6-bit characters)或32bits方式編碼(Word Alignment)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>固定長度整數</strong><strong> (Fixed Width Integer): </strong>例如假設一個8 bits整數,如果要呈現1這個數字,就會以0b00000001的方式來表示. 通常固定長度整數會用來處理習知的數值,最經典的例子就是Boolean 整數,就不會用 32bits來表示,而會以固定長度整數 1bit來代表一個Boolean.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>可變長度整數</strong><strong> (Variable Width Integer):</strong>可變長度整數,以VBR4來說,就是會以4bits為一組的方式呈現一個VBR欄位,其中最高Bit為0表示該VBR4的4bits組合尚未到結尾,若VBR4最高Bit為1表示該VBR4的數值已經結束.例如: 6 這數字二進位編碼為 0b0110,若用VBR4編碼為0b1110.或像是以8這數字二進位編碼來說為0b1000,若用VBR4編碼則為0b10010000,以每4Bits的VBR4解碼回來看就是把0b1001 最高bit忽略後 << 3 + 0b0000 也就會等於 0b1000. 以’LLVM Bitcode File Format’文件中的例子來說,0x1B ( =27) 來說,原本的二進位呈現方式為0b00011011,以可變長度整數方式來編碼的話,會以每三個bits一組來呈現,以這個例子來說就是 0b011 跟 0b011, 低位址的0b011 由於後面還有0b011要接續在一起,所以他的最高bit 會為0,表示還有接續的3bits內容,而最後的0b011 的最高bit會為1,表示已經到了結尾. 更直接一點來看就是把0x1B=27=0b00011011分拆成 24 + 3 也就是以 0b10110011 的 可變長度整數來呈現,Decode回來的方式就是 0b0011 最高bit為0,表示其後還有數值,目前值為3,而0b1011最高bit為1,表示目前數值已經到結尾,目前值為24 (0b011 << 3),所以 0b10110011解碼後的結果為 0x1B=27.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>字元編碼</strong><strong>(6-bit characters):</strong>6-bit characters encode common characters into a fixed 6-bit field. They represent the following characters with the following 6-bit values:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
‘a’ .. ‘z’ — 0 .. 25</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
‘A’ .. ‘Z’ — 26 .. 51</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
‘0’ .. ‘9’ — 52 .. 61</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
‘.’ — 62</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
‘_’ — 63</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
This encoding is only suitable for encoding characters and strings that consist only of the above characters. It is completely incapable of encoding characters not in the set.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>32bits</strong><strong>方式編碼</strong><strong>(Word Alignment):</strong>Occasionally, it is useful to emit zero bits until the bitstream is a multiple of 32 bits. This ensures that the bit position in the stream can be represented as a multiple of 32-bit words.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>LLVM Bitcode File Format/BitStream Nested Block</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關LLVM Bitcode格式的說明可以參考網頁<a href="http://llvm.org/docs/BitCodeFormat.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://llvm.org/docs/BitCodeFormat.html</a> ,而LLVM也提供一個方便解析LLVM BitCode檔案格式的工具 llvm-bcanalyzer,可用以讓開發者檢視LLVM BitCode檔案格式與對應欄位在編碼後的狀況.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LLVM的BitCode就像是Sun JVM HotSpot或是Google Android Dalvik VM ByteCode的角色一樣,都是提供一個中介的程式編碼IR(Intermediary Representation),再透過可以把這些IR程式碼格式編譯成為優化後的Native機械碼的方式,提供就像是Java JIT一樣可以跨平台但又考慮到不同處理器差異,可藉此提供接近原生程式碼編譯器(例如:GCC)的編譯效能,藉此提供一個高效率的編譯器與編譯後的指令集組合方案.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BitCode總共包含兩個部分,一個是BitStream Container Format,一個是被編碼在Container中的LLVM IR指令集編碼. BitStream Container Format就像是XML的資料結構描述方式,其中包括 Tags與Nested Structures,主要差異在於BitStream Container 為binary方式的編碼儲存,並且支援在這檔案中透過縮寫(Abbreviations)的方式來儲存相關的資料項目名稱,藉此縮小檔案的儲存空間.LLVM IR檔案中會嵌入(embedded ) Wrapper Structure讓LLVM 檔案可以被嵌入額外的資料訊息.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一個標準的BitCode檔案格式,檔案開頭前兩個Bytes會是’ 0x42, 0x43′ (=BC),接下來的兩個Bytes為 Application-Specific Magic Number,以筆者自己所編譯的BitCode檔案來說這兩個值為 ‘0xC0,0xDE’,一般的BitCode識別只需要判斷前面兩個Bytes,對特定的應用程式識別來說,則需要判斷完整的四個Bytes.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過工具llvm-bcanalyzer Dump BitCode檔案時,如果該區塊內容為空,會看到如下的區塊名稱宣告與結尾</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<BLOCKINFO_BLOCK/></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若該區塊中有包括相關描述內容,則可看到如下的區塊名稱宣告與結尾</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<PARAMATTR_BLOCK NumWords=25 BlockCodeSize=3></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
….</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</PARAMATTR_BLOCK></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每個區塊的描述都會以 <…> 的括號來區隔,並且對該區塊而言,會以 ‘/’ 作為一個區塊的結束,BitStream中的Block可以包括Nested 巢狀的內容結構,每一個Block都會包括一個依據內容屬性而訂定的特定ID.如下為以 Nested方式呈現的LLVM Block資料內容</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="806"><FUNCTION_BLOCK NumWords=5 BlockCodeSize=4> <strong>=></strong><strong>最一層的</strong><strong>Block,</strong><strong>其中包括其它第一層以後的內容</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<DECLAREBLOCKS op0=1/> <strong>=></strong><strong>第二層的</strong><strong>Block,</strong><strong>直接以</strong><strong> ‘/’ </strong><strong>收尾</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<CONSTANTS_BLOCK NumWords=1 BlockCodeSize=4> <strong>=></strong><strong>第二層的</strong><strong>Block,</strong><strong>其中包括其它第二層以後的內容</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<SETTYPE abbrevid=4 op0=17/> <strong>=></strong><strong>第三層的</strong><strong>Block,</strong><strong>直接以</strong><strong> ‘/’ </strong><strong>收尾</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INTEGER abbrevid=5 op0=2/> <strong>=></strong><strong>第三層的</strong><strong>Block,</strong><strong>直接以</strong><strong> ‘/’ </strong><strong>收尾</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</CONSTANTS_BLOCK></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_RET abbrevid=9 op0=48/><strong> =></strong><strong>第二層的</strong><strong>Block,</strong><strong>直接以</strong><strong> ‘/’ </strong><strong>收尾</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</FUNCTION_BLOCK></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於這些Block的定義在未來是可以根據需求擴充的,也因此在BitCode Format中會把Block 0定義為 Block Information區塊 (BLOCKINFO),用以儲存描述目前BitCode檔案中其他Block相關背景資訊的MetaData.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BitCode檔案格式內的MODULE_BLOCK區塊,是LLVM BitCode檔案格式Nested Block區塊巢狀架構最外層的Block, 檢視BitCoe Block架構與內容最好的方式就是透過指令 ‘ llvm-bcanalyzer -dump ‘,就可以把BitCode檔案格式所包含的Block資訊秀出,如下例子</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost test]# llvm-bcanalyzer -dump test.bc</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="810"><MODULE_BLOCK NumWords=167 BlockCodeSize=3><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<BLOCKINFO_BLOCK/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<PARAMATTR_BLOCK NumWords=4 BlockCodeSize=3></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY op0=4294967295 op1=2199023255584/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</PARAMATTR_BLOCK></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<TYPE_BLOCK_ID NumWords=15 BlockCodeSize=4></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<NUMENTRY op0=14/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INTEGER op0=8/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ARRAY abbrevid=9 op0=7 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<POINTER abbrevid=4 op0=1 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INTEGER op0=32/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<FUNCTION abbrevid=5 op0=0 op1=0 op2=3/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<POINTER abbrevid=4 op0=4 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INTEGER op0=64/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<FUNCTION abbrevid=5 op0=1 op1=0 op2=6/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<POINTER abbrevid=4 op0=7 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<POINTER abbrevid=4 op0=0 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<FUNCTION abbrevid=5 op0=1 op1=0 op2=3 op3=9/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<POINTER abbrevid=4 op0=10 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<POINTER abbrevid=4 op0=3 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<VOID/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</TYPE_BLOCK_ID></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<TRIPLE op0=120 op1=56 op2=54 op3=95 op4=54 op5=52 op6=45 op7=117 op8=110 op9=107 op10=110 op11=111 op12=119 op13=110 op14=45 op15=108 op16=105 op17=110 op18=117 op19=120 op20=45 op21=103 op22=110 op23=117/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<DATALAYOUT op0=101 op1=45 op2=112 op3=58 op4=54 op5=52 op6=58 op7=54 op8=52 op9=58 op10=54 op11=52 op12=45 op13=105 op14=49 op15=58 op16=56 op17=58 op18=56 op19=45 op20=105 op21=56 op22=58 op23=56 op24=58 op25=56 op26=45 op27=105 op28=49 op29=54 op30=58 op31=49 op32=54 op33=58 op34=49 op35=54 op36=45 op37=105 op38=51 op39=50 op40=58 op41=51 op42=50 op43=58 op44=51 op45=50 op46=45 op47=105 op48=54 op49=52 op50=58 op51=54 op52=52 op53=58 op54=54 op55=52 op56=45 op57=102 op58=51 op59=50 op60=58 op61=51 op62=50 op63=58 op64=51 op65=50 op66=45 op67=102 op68=54 op69=52 op70=58 op71=54 op72=52 op73=58 op74=54 op75=52 op76=45 op77=118 op78=54 op79=52 op80=58 op81=54 op82=52 op83=58 op84=54 op85=52 op86=45 op87=118 op88=49 op89=50 op90=56 op91=58 op92=49 op93=50 op94=56 op95=58 op96=49 op97=50 op98=56 op99=45 op100=97 op101=48 op102=58 op103=48 op104=58 op105=54 op106=52 op107=45 op108=115 op109=48 op110=58 op111=54 op112=52 op113=58 op114=54 op115=52 op116=45 op117=102 op118=56 op119=48 op120=58 op121=49 op122=50 op123=56 op124=58 op125=49 op126=50 op127=56 op128=45 op129=110 op130=56 op131=58 op132=49 op133=54 op134=58 op135=51 op136=50 op137=58 op138=54 op139=52 op140=45 op141=83 op142=49 op143=50 op144=56/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<GLOBALVAR op0=2 op1=1 op2=5 op3=9 op4=1 op5=0 op6=0 op7=0 op8=1/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<FUNCTION op0=5 op1=0 op2=0 op3=0 op4=1 op5=0 op6=0 op7=0 op8=0 op9=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<FUNCTION op0=8 op1=0 op2=1 op3=0 op4=0 op5=0 op6=0 op7=0 op8=0 op9=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<FUNCTION op0=11 op1=0 op2=1 op3=0 op4=0 op5=0 op6=0 op7=0 op8=0 op9=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<CONSTANTS_BLOCK NumWords=6 BlockCodeSize=4></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<SETTYPE abbrevid=4 op0=1/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<CSTRING abbrevid=10 op0=88 op1=58 op2=37 op3=120 op4=104 op5=10/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</CONSTANTS_BLOCK></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<FUNCTION_BLOCK NumWords=20 BlockCodeSize=4></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<DECLAREBLOCKS op0=1/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<CONSTANTS_BLOCK NumWords=4 BlockCodeSize=4></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<SETTYPE abbrevid=4 op0=3/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<NULL/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INTEGER abbrevid=5 op0=2/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<SETTYPE abbrevid=4 op0=9/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<CE_INBOUNDS_GEP op0=2 op1=0 op2=3 op3=5 op4=3 op5=5/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</CONSTANTS_BLOCK></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_ALLOCA op0=12 op1=3 op2=6 op3=3/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_ALLOCA op0=12 op1=3 op2=6 op3=3/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_STORE op0=8 op1=5 op2=0 op3=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_CALL op0=0 op1=0 op2=2/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_CAST abbrevid=7 op0=10 op1=3 op2=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_STORE op0=9 op1=11 op2=3 op3=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_LOAD abbrevid=4 op0=9 op1=3 op2=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_CALL op0=0 op1=0 op2=3 op3=7 op4=12/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INST_RET abbrevid=9 op0=5/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<VALUE_SYMTAB NumWords=1 BlockCodeSize=4></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY abbrevid=6 op0=9 op1=88/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</VALUE_SYMTAB></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</FUNCTION_BLOCK></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<METADATA_BLOCK NumWords=7 BlockCodeSize=3></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<METADATA_KIND op0=0 op1=100 op2=98 op3=103/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<METADATA_KIND op0=1 op1=116 op2=98 op3=97 op4=97/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<METADATA_KIND op0=2 op1=112 op2=114 op3=111 op4=102/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</METADATA_BLOCK></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<VALUE_SYMTAB NumWords=6 BlockCodeSize=4></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY abbrevid=6 op0=3 op1=112 op2=114 op3=105 op4=110 op5=116 op6=102/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY abbrevid=6 op0=1 op1=109 op2=97 op3=105 op4=110/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY abbrevid=6 op0=0 op1=46 op2=115 op3=116 op4=114/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY abbrevid=6 op0=2 op1=102 op2=117 op3=110 op4=99 op5=66/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</VALUE_SYMTAB></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</MODULE_BLOCK></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,為LLVM BitCode檔案格式中不同區塊描述時,Nested Block的示意圖,我們可以看到最外層為MODULE_BLOCK,其下依序包括FUNCTION_BLOCK,METADATA_BLOCK…etc,在Block之中還可以在包括其他的描述Block.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXlHHn7vMh3XCZTl0q6VlOLh2mRgQLUIp8Z8WConFqA8nZn0acCYJDse7WGYaIYD3YulAX6CBlNNKN8dSZHxBO0Xpjn58hh0fD7GpXRqKczGecSwjeH0tXYrNZ5JZcreBXe-cjcMA0-ls/s1600/image006%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="889" data-original-width="611" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXlHHn7vMh3XCZTl0q6VlOLh2mRgQLUIp8Z8WConFqA8nZn0acCYJDse7WGYaIYD3YulAX6CBlNNKN8dSZHxBO0Xpjn58hh0fD7GpXRqKczGecSwjeH0tXYrNZ5JZcreBXe-cjcMA0-ls/s1600/image006%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID 0-7預設給BitCode所定義的標準Block區塊.Blokc ID 8 以後為應用程式所特定使用的ID,像是Block ID 12為用以呈現函式實作本體(Function Body)的LLVM IR(Intermediary Representation)內容.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>LLVM IR is defined with the following blocks</strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">Block ID</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">BLOCKINFO主要用以儲存描述其它Block區塊資訊的MetaData,根據文件的定義主要包括,SETBID(Code 1,[SETBID (#1), blockid]),用來表示目前描述的資訊是哪個Block ID,在BLOCKINFO中根據所要描述的Block個數,就可以有多筆SETBID宣告. DEFINE_ABBREV([DEFINE_ABBREV, …])在BLOCKINFO中主要用以表示目前所描述Block Id的縮寫定義.BLOCKNAME (Code 2,[BLOCKNAME, …name…])是非必要的欄位,用以記錄Block的名稱字串.SETRECORDNAME (Code 3,[SETRECORDNAME, RecordID, …name…])是非必要欄位,會以第一個參數作為Record ID,其它部分則為這筆Record的名稱字串.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為筆者所舉範例的 BLOCKINFO_BLOCK Summary內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID #0 ( BLOCKINFO_BLOCK):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Instances: 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total Size: 637b/79.62B/19W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent of file: 11.7096%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num SubBlocks: 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Abbrevs: 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Records: 0</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">1 — 7</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">Block IDs 1-7 保留,用以作為未來的擴充之用.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">8</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">MODULE_BLOCK (=FIRST_APPLICATION_BLOCKID )<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這是BitCode檔案格式中最外層的Block,在這Block內會包括整個模組內其它Block的描述內容. 根據目前的定義,MODULE_BLOCK可以包括以下的Sub BLOCK區塊內容.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,BLOCKINFO</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,PARAMATTR_BLOCK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,TYPE_BLOCK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,TYPE_SYMTAB_BLOCK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,VALUE_SYMTAB_BLOCK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,CONSTANTS_BLOCK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,FUNCTION_BLOCK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,METADATA_BLOCK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為筆者所舉範例的 MODULE_BLOCK Summary內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID #8 (MODULE_BLOCK):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Instances: 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total Size: 2544b/318.00B/79W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent of file: 46.7647%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num SubBlocks: 7</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Abbrevs: 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Records: 6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent Abbrevs: 0.0000%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Record Histogram:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Count # Bits % Abv Record Kind</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3 225 FUNCTION</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 69 GLOBALVAR</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 1761 DATALAYOUT</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 303 TRIPLE</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除了Sub Block外, MODULE_BLOCK主要包括以下資訊內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[VERSION, version#] : VERSION (Code 1) 用以表示目前所支援的格式版本</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[TRIPLE, …string…]: TRIPLE (Code 2) 用以儲存Target Triple Specification 字串字元.如下為筆者環境的例子</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<TRIPLE op0=120 op1=56 op2=54 op3=95 op4=54 op5=52 op6=45 op7=117 op8=110 op9=107 op10=110 op11=111 op12=119 op13=110 op14=45 op15=108 op16=105 op17=110 op18=117 op19=120 op20=45 op21=103 op22=110 op23=117/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[DATALAYOUT, …string…]: DATALAYOUT (Code 3)用以儲存 target datalayout Specification 字串字元.如下為筆者環境的例子</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<DATALAYOUT op0=101 op1=45 op2=112 op3=58 op4=54 op5=52 op6=58 op7=54 op8=52 op9=58 op10=54 op11=52 op12=45 op13=105 op14=49 op15=58 op16=56 op17=58 op18=56 op19=45 op20=105 op21=56 op22=58 op23=56 op24=58 op25=56 op26=45 op27=105 op28=49 op29=54 op30=58 op31=49 op32=54 op33=58 op34=49 op35=54 op36=45 op37=105 op38=51 op39=50 op40=58 op41=51 op42=50 op43=58 op44=51 op45=50 op46=45 op47=105 op48=54 op49=52 op50=58 op51=54 op52=52 op53=58 op54=54 op55=52 op56=45 op57=102 op58=51 op59=50 op60=58 op61=51 op62=50 op63=58 op64=51 op65=50 op66=45 op67=102 op68=54 op69=52 op70=58 op71=54 op72=52 op73=58 op74=54 op75=52 op76=45 op77=118 op78=54 op79=52 op80=58 op81=54 op82=52 op83=58 op84=54 op85=52 op86=45 op87=118 op88=49 op89=50 op90=56 op91=58 op92=49 op93=50 op94=56 op95=58 op96=49 op97=50 op98=56 op99=45 op100=97 op101=48 op102=58 op103=48 op104=58 op105=54 op106=52 op107=45 op108=115 op109=48 op110=58 op111=54 op112=52 op113=58 op114=54 op115=52 op116=45 op117=102 op118=56 op119=48 op120=58 op121=49 op122=50 op123=56 op124=58 op125=49 op126=50 op127=56 op128=45 op129=110 op130=56 op131=58 op132=49 op133=54 op134=58 op135=51 op136=50 op137=58 op138=54 op139=52 op140=45 op141=83 op142=49 op143=50 op144=56/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[ASM, …string…]: ASM (Code 4)用以儲存個別的BitCode Assembly區塊,不同的Assembly區塊會以0x0A NewLine來區隔開來.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[SECTIONNAME, …string…]: SECTIONNAME (Code 5)用以儲存不同Section的名稱字串.每一個Section名稱都會對應到一筆 SECTIONNAME資料.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其它包括[DEPLIB, …string…] (Code 6),[GLOBALVAR, pointer type, isconst, initid, linkage, alignment, section, visibility, threadlocal] (Code 7),[FUNCTION, type, callingconv, isproto, linkage, paramattr, alignment, section, visibility, gc] (Code 8),[ALIAS, alias type, aliasee val#, linkage, visibility] (Code 9),[PURGEVALS, numvals] (Code 10),[GCNAME, …string…] (Code 11) 都是MODULE_BLOCK中所包括的資訊,筆者在此就不一一說明,有興趣的開發者可以自行參與技術文件.</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">9</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">PARAMATTR_BLOCK (Id=9)包含一個用以描述每個Function 參數Parameters屬性的Table.在這表格中的Entry會被FUNCTION區塊的每個Parameters欄位所參考.或是被FUNCTION區塊中的INST_INVOKE與INST_CALL的ATTR欄位所參考.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每筆在PARAMATTR_BLOCK 欄位中的資料,都會是唯一的</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PARAMATTR_BLOCK中的資料格式如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[ENTRY, paramidx0, attr0, paramidx1, attr1…]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者舉手中BitCode的 PARAMATTR_BLOCK為例,內容如下所示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<PARAMATTR_BLOCK NumWords=25 BlockCodeSize=3></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY op0=4294967295 op1=2199023256096/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY op0=4294967295 op1=2199023255584/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY op0=1 op1=4294967296 op2=4294967295 op3=32/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY op0=4294967295 op1=32/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY op0=1 op1=4294967296 op2=2 op3=4294967296 op4=4294967295 op5=32/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY op0=0 op1=64 op2=4294967295 op3=32/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ENTRY op0=2 op1=4294967296 op2=4294967295 op3=32/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</PARAMATTR_BLOCK></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為筆者所舉範例的 PARAMATTR_BLOCK Summary內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID #9 (PARAMATTR_BLOCK):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Instances: 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total Size: 189b/23.62B/5W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent of file: 3.4743%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num SubBlocks: 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Abbrevs: 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Records: 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent Abbrevs: 0.0000%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Record Histogram:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Count # Bits % Abv Record Kind</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 111 ENTRY</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">10</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">TYPE_BLOCK (ID=10) 包括了一個在這模組中所使用的Type Table列表,用以表示在這BitCode模組中所參考到的形態.除了NUMENTRY外的資料會產生一個單一型態Type的Entry記錄,包括指令集,常數,MetaData,Type Symbol Table Entry,或其他Type操作單元資料. 每筆在TYPE_BLOCK中的資料都會確保是唯一的.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者舉手中BitCode的 TYPE_BLOCK為例,內容如下所示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<TYPE_BLOCK_ID NumWords=35 BlockCodeSize=4></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<NUMENTRY op0=51/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INTEGER op0=8/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<ARRAY abbrevid=9 op0=13 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<POINTER abbrevid=4 op0=1 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……………..</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<VOID/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<INTEGER op0=1/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<FUNCTION abbrevid=5 op0=0 op1=0 op2=46 op3=18 op4=18 op5=7 op6=17 op7=47/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<POINTER abbrevid=4 op0=48 op1=0/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<METADATA/></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</TYPE_BLOCK_ID></div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">11</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">CONSTANTS_BLOCK 主要用以儲存在這模組內或所包含的函式所使用到的常數資料,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為筆者所舉範例的 CONSTANTS_BLOCK Summary內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID #11 (CONSTANTS_BLOCK):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Instances: 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total Size: 454b/56.75B/14W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent of file: 8.3456%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Average Size: 227.00/28.38B/7W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tot/Avg SubBlocks: 0/0.000000e+00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tot/Avg Abbrevs: 4/2.000000e+00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tot/Avg Records: 7/3.500000e+00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent Abbrevs: 71.4286%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Record Histogram:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Count # Bits % Abv Record Kind</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3 24 100.00 SETTYPE</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 52 CE_INBOUNDS_GEP</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 52 100.00 CSTRING</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 12 100.00 INTEGER</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 16 NULL</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">12</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">FUNCTION_BLOCK,主要用以描述Function的本體.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為筆者所舉範例的 FUNCTION_BLOCK Summary內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID #12 (FUNCTION_BLOCK):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Instances: 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total Size: 418b/52.25B/13W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent of file: 7.6838%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num SubBlocks: 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Abbrevs: 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Records: 10</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent Abbrevs: 30.0000%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Record Histogram:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Count # Bits % Abv Record Kind</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2 92 INST_CALL</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2 80 INST_STORE</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2 80 INST_ALLOCA</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 15 100.00 INST_LOAD</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 10 100.00 INST_RET</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 18 100.00 INST_CAST</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 22 DECLAREBLOCKS</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">13</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">TYPE_SYMTAB_BLOCK,主要用以描述Type Symbol Table.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">14</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">VALUE_SYMTAB_BLOCK,主要用以描述數值的Symbol Table<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為筆者所舉範例的 VALUE_SYMTAB_BLOCK Summary內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID #14 (VALUE_SYMTAB):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Instances: 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total Size: 338b/42.25B/10W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent of file: 6.2132%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Average Size: 169.00/21.12B/5W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tot/Avg SubBlocks: 0/0.000000e+00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tot/Avg Abbrevs: 0/0.000000e+00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tot/Avg Records: 5/2.500000e+00</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent Abbrevs: 100.0000%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Record Histogram:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Count # Bits % Abv Record Kind</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 210 100.00 ENTRY</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">15</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">METADATA_BLOCK,主要用以描述MetaData項目.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為筆者所舉範例的 METADATA_BLOCK Summary內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID #15 (METADATA_BLOCK):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Instances: 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total Size: 285b/35.62B/8W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent of file: 5.2390%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num SubBlocks: 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Abbrevs: 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Records: 3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent Abbrevs: 0.0000%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Record Histogram:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Count # Bits % Abv Record Kind</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3 195 METADATA_KIND</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">16</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">METADATA_ATTACHMENT,主要用以記錄跟函式指令數值有關的MetaData資料.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84">17</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725">TYPE_BLOCK_ID<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為筆者所舉範例的 TYPE_BLOCK_ID Summary內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Block ID #17 (TYPE_BLOCK_ID):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Instances: 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total Size: 541b/67.62B/16W</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent of file: 9.9449%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num SubBlocks: 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Abbrevs: 6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Records: 15</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Percent Abbrevs: 66.6667%</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Record Histogram:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Count # Bits % Abv Record Kind</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6 48 100.00 POINTER</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3 49 100.00 FUNCTION</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3 78 INTEGER</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 16 100.00 ARRAY</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 16 VOID</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 22 NUMENTRY</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="84"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="725"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於Nested Block的架構,可以支援有從屬繼承關係的資料屬性或內容,並且可以在Block結構分析時,可以先在其上的Block Id判斷這是否為應該要處理的資料內容,而節省檔案結構分析所需的時間,例如Block ID 3的Nested Block範圍內還有Block ID 13與8,若Block ID 3是目前檔案分析所不需要參考的內容,就可以直接往其後不在Block ID 3內的Block來做分析處理,對系統運作效率上可以得到改善.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>LLVM Calling Convention</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Calling Convention是每一個語言在處理函式呼叫時,暫存器要如何配置與返回值要如何處理的重要原則,而一個函式呼叫Caller/Callee雙方要能順利執行,也都必須要支持一致的Calling Convention行為,而LLVM基於一個要達成跨平台高執行效率的角色,自然在Call Convention的技術支援上,也該有值得我們深入關注的部份,目前筆者所理解的LLVM主要支援以下的Calling Convention機制,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,C Calling Convention(CCC):當函式呼叫沒有指定Calling Convention時,預設就會支援這個C Calling Convention模式.會把函式參數由右而左推到Stack中,而被呼叫端則依序透過Stack把函式參數取出. This calling convention supports varargs function calls and tolerates some mismatch in the declared prototype and implemented declaration of the function (as does normal C).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,Fast Calling Convention (FastCC):顧名思義,這是一個會盡可能讓呼叫很快速的Calling Convention機制,在函式呼叫過程中所傳遞的函式參數會以處理器暫存器來傳遞,並無需考慮特定的 specified ABI (Application Binary Interface)標準.This calling convention does not support varargs and requires the prototype of all callees to exactly match the prototype of the function definition.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Cold Calling Convention: 這是一個讓不是很常被執行的函式,可以在呼叫端有效率的執行呼叫.主要的差異在於在一個函式呼叫的熱區中,有關的參數與數值都會儲存在處理器的暫存器中,如果為了一個非熱區的函式還要把這些暫存器備份到相對速度比較慢的外部記憶體,如此則會對執行效率產生影響.This calling convention does not support varargs and requires the prototype of all callees to exactly match the prototype of the function definition.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,GHC Convetion (cc10, Glasgow Haskell Compiler): 這是一個由Glasgow Haskell編譯器所支援的Calling Convention.函式參數的傳遞主要透過處理器暫存器進行,並會Disable被呼叫端對處理器暫存器的保存與回復動作,這種呼叫方式主要應用在對執行效能有較高要求的函式呼叫中.如同 Fast Calling Convention一樣, GHC Calling Convention也支持Tail Call的Calling Convention.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在函式呼叫效能的改善上,LLVM也支援Tail Call機制,例如在x86上可讓Caller與Callee在呼叫時共用同樣的Stack Frame,例如FuncA->FuncB->FuncC的呼叫,基於Tail Call機制,可以減少其中透過 call 與重新Push Stack的成本,讓FuncA->FuncB->FuncC可以透過 Jmp與共用 Stack方式,而在FuncC結束時,也可以直接返回到FuncA讓函式呼叫的效率提高,LLVM的Tail Call支援是有平台限制的,且必須Caller與Callee的函式宣告為Fast Calling Convention或是 GHC Convention型態.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
法拉第曾說,<strong><span style="text-decoration-line: underline;">“ </span></strong><strong><span style="text-decoration-line: underline;">人心是偏向於錯誤的</span></strong><strong><span style="text-decoration-line: underline;">,</span></strong><strong><span style="text-decoration-line: underline;">人會在自己強烈需要的事情上</span></strong><strong><span style="text-decoration-line: underline;">,</span></strong><strong><span style="text-decoration-line: underline;">欺騙自己</span></strong><strong><span style="text-decoration-line: underline;">.</span></strong><strong><span style="text-decoration-line: underline;">即使尋找印證,也要符合自己的欲望</span></strong><strong><span style="text-decoration-line: underline;">“</span></strong> ,筆者在整理本文時雖盡可能確保資料的正確性,然若有所遺漏也歡迎各位指正.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LLVM要介紹與說明的細節非常多,在這篇文章中筆者只選擇自己感興趣的LLVM技術加以探究,限於篇幅也難以透過一篇文章就把這麼精采的技術項目說明完畢,對LLVM Dig-in越深,也越加覺得這技術在未來發展上的潛力無窮. 隨著Google在未來把PNaCl應用到瀏覽器中,Apple也會把LLVM技術紮根於Mac OS X上,可預見的未來LLVM技術將會更加普及,LLVM不但支援跨平台,還兼顧到執行效率與所耗資源不高的特性,對於現今手機或消費性電子的軟體執行效能改善,將會有相當的助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-13543356511519064142017-06-03T17:33:00.002-07:002017-06-03T17:33:36.125-07:00GDB筆記.<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
GDB筆記.</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
loda.chou</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<a href="mailto:hlchou@mail2000.com.tw" style="color: #666666; font-weight: bold; text-decoration-line: none;">hlchou@mail2000.com.tw</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
記得以前玩電腦遊戲時,Game Buster這套古董級的軟體是筆者玩遊戲時修改的利器,在MS-DOS時代下,這類系統常駐軟體會透過按鍵中斷組合鍵喚醒(記憶無誤的話,應該是連續兩下Ctrl鍵).隨後,開始有機會撰寫MS-Windows上的程式,” Ctrl + D” 喚醒SoftICE相信是很多在Windows下軟體破解或開發驅動程式的人深刻的回憶.對很多初學者而言,這種Console模式的除錯器總讓人覺得距離遙遠,能不碰或少背些指令就不碰.而能製作出Windows上這套經典SoftICE的人想必來頭也不小,其中一位開發者就是Matt Pietrek,也是”Windows 95 System Programming Secrets”這本 Windows 95系統探索經典書籍的作者(台灣譯本為”Windows95系統程式設計-大奧秘”),在Microsoft Systems Journal 對系統開發者深具影響力的年代,Matt的 “Under The Hood” 專欄,是對系統層級開發者很棒的滋補養分.直到2006年4月,NuMega宣布將SoftICE的維護期只延續到隔年的3月,並替這套經典軟體畫下句點. 目前Windows上,首推的Console除錯工具應該就是微軟自己維護的WinDbg(參考網頁<a href="http://msdn.microsoft.com/en-us/windows/hardware/gg463009" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://msdn.microsoft.com/en-us/windows/hardware/gg463009</a>).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每一套Console除錯器,從開始使用到能充分掌握,其實都需要一點時間去熟悉處理器,作業系統與該Console除錯器上各類常用指令.但面對現實,相信很多人都跟我有類似的經驗,在某一個時間點熟悉一個開發工具,但因著開發環境的轉換,時間久了,自己也專注在新的產品開發上,對於過往工具的熟韌度就又一點一滴的流失.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這篇文章的誕生,主要緣於自己希望為GDB寫一篇值得紀念的文章,二者也是把自己對這套工具的使用心得記錄下來,希望能讓有同樣需求的開發者得到助益. 本文的撰寫,會以筆者自身的經驗為主,希望提供的資訊不只是使用GDB,也能了解背後運作的原理,最後,在實務上,如果遇到現場損毀時,能如何透過有限的線索去找出問題發生的原因.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而GDB之所以強大,除了自身體系的完整外,提供給GDB系統層級除錯能力的Linux Kernel PTrace核心,是讓GDB之所以能發揮作用的原因. Linux Kernel 透過ptrace System Call讓GDB可以去Attach運作中的Process,或透過TraceME命令讓應用程式從一開始載入就進入GDB除錯的範圍裡,包括像是GDB支援對除錯程式的跨行程記憶體修改,設定BreakPoint/WatchPoint,單步除錯…等,都有賴於Linux Kernel ptrace System Call的支援.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
不免俗的,筆者選擇MS-Windows作為對比的環境,跟Linux Kernel Ptrace一樣,MS Windows也由核心提供Win32 Debug API除錯介面,記得之前的工作,曾有需求要在Windows平台上為產品x86模擬器提供自製的除錯介面,但又以不希望使用者需額外安裝Visual Studio的前提,當時的解決方案就是使用Windows內建的Win32 Debug API(<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms679303(v=vs.85).aspx" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://msdn.microsoft.com/en-us/library/windows/desktop/ms679303(v=vs.85).aspx</a> ),並藉此搭建屬於自己產品化需求的除錯環境,像是Win32 PDB Debug Symbol解析,可用以把Symbol/位址與行數對應回來,單步除錯,設定Break-Point..等. 這套Win32 Debug API可讓開發者呼叫CreateProcess產生要被除錯的Debug Child,並由Debug Parent透過WaitForDebugEvent接收並處理來自被除錯Debug Child的Debug Event. 跟透過Linux Kernel Ptrace除錯時要由Debug Parent透過fork產生Debug Child,再透過wait去接收來自Debug Child的Notification,實現的概念非常類似.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但兩者還是有一些差異,像是Win32 Debug API有把PDB Symbol Decoder都包裝好了(可藉由QueryInterface 取得__uuidof(IDebugSymbols2)介面,並透過GetOffsetByName/GetLineByOffset/StartSymbolMatch/GetNextSymbolMatch/GetTypeName/GetTypeSize/GetOffsetTypeId進行PDB Symbol的查詢),這對於在Win32環境撰寫除錯介面的開發者而言可省去不少工作量. 反觀GDB本身需額外實作DWARF2 Symbol Decode,以便讓除錯器功能完整,但也基於此,我們可以透過GDB對DWARF2的實現,更進一步的了解除錯機制的設計原理.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GDB 是一套free software並在受GNU General Public License (GPL)的保護下發佈,最早是由Richard Stallman (<a href="http://stallman.org/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://stallman.org/</a>) 在1990年代中期投入開發,並以GDB(GNU symbolic debugger)為命名,讓這套Unix環境下的經典除錯工具正式誕生.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而這樣一套強大的除錯工具也絕非一人之力所能完成,像是Michael Tiemann主要貢獻了GNU C++ 在GDB中的支援, David Johnson貢獻了GDB原本的COFF檔案格式支援, Pace Willison則支援encapsulated COFF檔案格式, Adam de Boor 與 Bradley Davis貢獻了ISI Optimum V的支援, Per Bothner,Noboyuki Hikichi與Alessandro Forin 貢獻了對 MIPS 的支援, Jean-Daniel Fekete貢獻了Sun 386i的支援, Chris Hanson貢獻了HP9000的支援, Noboyuki Hikichi與 Tomoyuki貢獻了Sony/News OS3的支援, David Johnson貢獻了對Umax的支援, Jyrki Kuoppala貢獻了對Altos 3068的支援, Je Law貢獻了對HP PA與SOM的支援,Keith Packard 貢獻了對NS32K 支援. Doug Rabson 貢獻了對Acorn Risc Machine 支援. Bob Rusk 貢獻了對Harris Nighthawk CX-UX 支援. Chris Smith 貢獻了對Convex support (and Fortran debugging)支援. Jonathan Stone 貢獻了對Pyramid 支援. Michael Tiemann 貢獻了對SPARC 支援. Tim Tucker 貢獻了對 Gould NP1 與 Gould Powernode支援. Pace Willison 貢獻了對Intel 386 支援. Jay Vosburgh 貢獻了對Symmetry 支援. Rich Schaefer 與 Peter Schauer 貢獻了對SunOS shared libraries支援…等.並在GDB 4.x進一步支援了BFD函式庫,並藉此可以支援多種LE-Object檔案格式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
總結前述討論,GDB的誕生確實很不容易,由於它功能的強大,與跨平台的彈性,熟悉這套工作對於開發者而言,相信會是有其價值與意義的!!</div>
<h1 id="15582_%e4%bd%bf%e7%94%a8gd_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
使用GDB開始除錯前</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GDB是如何知道編譯後的程式碼與Source Code的關係呢? 跟前面提到的Windows PDB格式一樣,ELF檔案在透過GCC編譯時,我們可以透過-g的參數,讓GCC為編譯的執行檔案加上 DWARF 2的除錯資訊內容,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以從Code Sourcery下載編譯好的Toolchain 網址是http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 (網站http://www.codesourcery.com/sgpp/lite/arm/portal/release1600) 下載ARM eabi gcc Cross Compiler工具.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來我們以如下TestA.c程式碼為例,來說明編譯後是如何透過DWARF 2資訊,去把記憶體位址與行數給對應回來,並會驗證在有無DWARF 2資訊下,對應到GDB操作TestA的結果</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="394">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int FuncB(int X)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y=X+40;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y*=X+20;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“FuncB:%ld\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int FuncA(int X)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Z;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y=X+10;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y*=X+30;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Z=FuncB(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“FuncA:%ld\n”,Z);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Y=99;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y=FuncA(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“main:%ld\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示以ARM GCC編譯TestA程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-none-linux-gnueabi-gcc TestA.c -g -o TestA</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然後透過 ARM ObjDump進行反組譯與透過readelf判讀 DWARF 2的資訊,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-none-linux-gnueabi-objdump -x -D TestA > TestA.asm</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
readelf TestA –debug-dump</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
結果如下所示,參考DWARF 2的Section “.debug_line”,筆者以函式 main為例來說明</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="86">行數</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="724">Source Code</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="86">21<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
22</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
25</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
26</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
27</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="724">int main()<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int Y=99;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y=FuncA(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“main:%ld\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在筆者的ARM處理器上,應用程式載入到記憶體後的起點為0x00008000,以這次驗證的TestA來說,參考ELF檔頭start address 落在.text section的起點0x00008380,也正好是在執行到應用程式進入點main以前的前置函式_start所在位置,並由_start函式把main函式位址當做參數,帶入呼叫__libc_start_main , 而__libc_start_main原型為如下,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int __libc_start_main(int *(main) (int, char * *, char * *), int argc, char * * ubp_av, void (*init) (void), void (*fini) (void), void (*rtld_fini) (void), void (* stack_end));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以testA來說,main函式最後被擺放的記憶體位址為0x84e0,會在前置函式執行後才被正式執行到,如下所示,參考DWARF 2中的 .debug_line section中的內容,可以看到每一行Source Code都會有對應的描述,並可對應到實際ARM機械碼所在的記憶體範圍,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="351">.debug_line</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="459">反組譯內容</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="351">Special opcode 119: advance Address by 16 to <strong><span style="text-decoration-line: underline;">0x84e0</span></strong>and Line by 2 to 22<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Special opcode 90: advance Address by 12 to <strong><span style="text-decoration-line: underline;">0x84ec</span></strong> and Line by 1 to 23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Special opcode 62: advance Address by 8 to <strong><span style="text-decoration-line: underline;">0x84f4</span></strong> and Line by 1 to 24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Special opcode 90: advance Address by 12 to <strong><span style="text-decoration-line: underline;">0x8500</span></strong>and Line by 1 to 25</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Special opcode 118: advance Address by 16 to <strong><span style="text-decoration-line: underline;">0x8510</span></strong>and Line by 1 to 26</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Special opcode 34: advance Address by 4 to <strong><span style="text-decoration-line: underline;">0x8514</span></strong> and Line by 1 to 27</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="459">000084e0 <main>:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">84e0</span></strong>: e92d4800 push {fp, lr}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84e4: e28db004 add fp, sp, #4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84e8: e24dd008 sub sp, sp, #8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">84ec</span></strong>: e3a03063 mov r3, #99 ; 0x63</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84f0: e50b3008 str r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">84f4</span></strong>: e51b0008 ldr r0, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84f8: ebffffe0 bl 8480 <FuncA></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84fc: e50b0008 str r0, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">8500</span></strong>: e59f3018 ldr r3, [pc, #24] ; 8520 <main+0x40></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8504: e1a00003 mov r0, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8508: e51b1008 ldr r1, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
850c: ebffff98 bl 8374 <_init+0x44></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">8510</span></strong>: e3a03000 mov r3, #0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8514: e1a00003 mov r0, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8518: e24bd004 sub sp, fp, #4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
851c: e8bd8800 pop {fp, pc}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8520: 00008610 andeq r8, r0, r0, lsl r6</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於上述反組譯main函式內容與 .debug_line的DWARF2資訊,我們可以進一步用GDB指令 (gdb) disas /m main 來得到一個綜合的結果檢視,如下所示,可以看到基於 .debug_info的內容,能把C程式Source Code對應到編譯後ARM指令集的對應位址. (隨著編譯器優化程度的不同,對應結果可能會有差異.)</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="810">(gdb) disas /m main<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dump of assembler code for function main:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
22 {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000084e0 <+0>: push {r11, lr}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000084e4 <+4>: add r11, sp, #4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000084e8 <+8>: sub sp, sp, #8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
23 int Y=99;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000084ec <+12>: mov r3, #99 ; 0x63</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000084f0 <+16>: str r3, [r11, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
24 Y=FuncA(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000084f4 <+20>: ldr r0, [r11, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000084f8 <+24>: bl 0x8480 <FuncA></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000084fc <+28>: str r0, [r11, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
25 printf(“main:%ld\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008500 <+32>: ldr r3, [pc, #24] ; 0x8520 <main+64></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008504 <+36>: mov r0, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008508 <+40>: ldr r1, [r11, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000850c <+44>: bl 0x8374 <printf></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
26 return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008510 <+48>: mov r3, #0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
27 }</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008514 <+52>: mov r0, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008518 <+56>: sub sp, r11, #4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000851c <+60>: pop {r11, pc}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008520 <+64>: andeq r8, r0, r0, lsl r6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
End of assembler dump.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
雖然透過GDB能檢視編譯後的ARM指令集與Source Code對應關係,但在實務操作上,經過編譯器更深度的優化後,上述優化程度較低,容易識別的.debug_line與機械碼的對應關係就可能會有所差異,在產品化階段,解決問題最棒的不二法門,還是要了解你所使用的處理器與指令集,並基於透過GDB的操作得到的資訊,加速問題收斂的效率與準確度.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對筆者來說,GDB是一個在產品化階段,可以進行事後分析問題的好工具,只要有問題發生的Core-Dump,帶有DWARF資訊的ELF執行檔與.so動態函式庫檔案,一個基本的 GDB問題分析流程就可展開.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但實務上,除錯的過程不總是完美的,例如Core-Dump檔案損毀,GDB Back Trace因為編譯的ARM代碼對SP暫存器有額外操作或是有Stack覆蓋問題,以致無法順利回推.此外像是牽涉到ARM處理器的ARMv32/Thumb Mode轉態問題…等,都需要有額外的系統知識進行現場狀況排除.筆者會建議避免過度仰賴除錯器的結果,在問題分析上,可看待GDB為處理繁瑣解析過程的 ”工具”,但系統問題發生的真正原因, 還是需仰賴問題分析者對系統問題的理解深度,來做最後的判定與解決.</div>
<h1 id="15582_gdb%e7%9a%84%e5%8e%9_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
GDB的原理</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先,以下所列舉的Linux Kernel Source Code實作會以3.0.8為依據,而所參考的GDB Source Code版本為 7.4(<a href="http://www.gnu.org/software/gdb/download/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.gnu.org/software/gdb/download/</a> ),若有不同版本間實作上的差異,還請以各位所使用的開發環境為依據. 有關GDB在ARM Linux的實作,主要可以參考的代碼為gdb-7.4/gdb/arm-linux-nat.c(Linux ARM native support )與gdb-7.4/gdb/arm-linux-tdep.c(Linux ARM target support).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux 提供讓 Ptrace Debug Parent對Debug Child進行除錯機制的ptrace函式,是一個 Linux Kernel的System Call介面 (sys_ptrace 編號為 26.),可讓Debug Parent控制Debug Child的執行,檢視與改變Debug Child的記憶體內容與暫存器.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Linux環境下,ptrace函式的C原型為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
long ptrace(enum __ptrace_request request, pid_t pid,void *addr, void *data);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Ptrace Debug Parent接上Debug Child可以有兩種方式,第一個是Process已經被執行後, 開發者希望在Run-Time接上進行除錯,此時可以透過PTRACE_ATTACH命令去Attach指定的Process ID.第二個類情況是Process尚未被執行,就可以透過PTRACE_TRACEME命令,去Fork出一個Debug Child Process,然後在該Process行程空間中再透過exec指令去執行外部希望被載入除錯的應用程式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當行程處於被除錯的狀態,除了SIGKILL有預設的行為外,Debug Child會在收到每一個Signal時就暫停執行,並由Debug Parent透過wait回傳Notification,檢視當下Debug Child的狀態. 當Debug Parent完成除錯工作後,可以選擇透過PTRACE_KILL結束Debug Child的執行,或透過PTRACE_DETACH解除目前除錯的狀態.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若一個正在執行的 Process已經有一個Parent Process會透過wait去接收它的Notification,當這個Child Process被Debug Parent透過 PTRACE_ATTACH給接上,成為被除錯的Debug Child Process後,這個Child Process原本的Parent Process就無法再透過wait去收到原本Child Process的Notification.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Debug Parent與Debug Child透過Linux Kernel所提供的ptrace System Call進行除錯的運作概念,可參考下圖所示.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-fH_f5xM-RgoheUC9M_ondVlve8aF2EAtO52kOILw-KBHBUse00OAM1l1lXj0Xt_C4sZowSa5CjQ_dbdBoqmj6G8IOPRMe1fdulkNfUUL23e6YUhD9YL3ks511-2JWVW_P2VGaDO0h0I/s1600/image002%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="247" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-fH_f5xM-RgoheUC9M_ondVlve8aF2EAtO52kOILw-KBHBUse00OAM1l1lXj0Xt_C4sZowSa5CjQ_dbdBoqmj6G8IOPRMe1fdulkNfUUL23e6YUhD9YL3ks511-2JWVW_P2VGaDO0h0I/s1600/image002%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Debug Parent可透過wait函式接收來自Debug Child的Notification,例如Debug Parent收到wait傳回的WIFSTOPPED狀態,就可以判斷是否為剛才設定的BreakPoint/WatchPoint被觸發,以檢視Debug Child當下的執行狀態,或透過PTRACE_SINGLESTEP以Single Step執行Debug Child時,每執行完一個指令,也會讓Debug Child進入Stop狀態.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下演示一個基本的Ptrace Debug Parent與Debug Child互動的範例程式,可以看到當除錯程式fork出要被除錯的Process後,會先透過PTRACE_TRACEME去Enable Debug Child處於被除錯的狀態,而一個Debug Child在執行過PTRACE_TRACEME後,在第一個System Call執行前,會進入Stop狀態,等待來自Debug Parent所下的ptrace Command,以進行後續除錯流程.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="807">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <string.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <errno.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <unistd.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <signal.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <sys/ptrace.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <sys/user.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <sys/reg.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vPid;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vGetChildStatus;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long vInstCount;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Keep the record of how many inst. child executed.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vInstCount=0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if((vPid = fork()) == 0) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//In Child</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(<strong>PTRACE_TRACEME</strong>, 0, 0, 0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“In Child, try to call /bin/ls command.\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>execl</strong>(“/bin/ls”, “”, 0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} else {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//In Parent</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Keep Child tracing through forks, vforks, execs and clones</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(PTRACE_SETOPTIONS, vPid, 0, PTRACE_O_TRACEFORK|PTRACE_O_TRACEVFORK|PTRACE_O_TRACECLONE|PTRACE_O_TRACEEXEC);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
while(1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{//Busy 1 Loop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Wait for Child to Stop at Next Inst.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(<strong>wait</strong>(&vGetChildStatus)==-1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Failed to wait.\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (<strong>WIFSTOPPED</strong>(vGetChildStatus))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{//Child is under Stop-Stat.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vInstCount++;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(ptrace(<strong>PTRACE_SINGLESTEP</strong>, vPid, 0, 0)!=0)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
perror(“Singl Step Error”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Continue to enanle child under Single-Step Mode.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else if (<strong>WIFEXITED</strong>(vGetChildStatus))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Child exited with status %d\n”,WEXITSTATUS(vGetChildStatus));</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (<strong>WIFSIGNALED</strong>(vGetChildStatus))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Child was terminated by signal %d. “,WTERMSIG(vGetChildStatus));</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}//End of Busy 1 Loop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Total Instrution Count:%ld\n”,vInstCount);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般來說BreakPoint 可以分為以下幾類</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,Software BreakPoint : 在ARM中可以特定的指令集(例如:0xffffffff 就可以觸發Undefined Instruction Exception.),放在要觸發軟體中斷的記憶體位址,以便在該指令被執行到時,透過觸發Undefined Instruction Exception以作為軟體中斷機制</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,Hardware BreakPoint : ARM透過CoProcessor 14支援的硬體BreakPoint,當ARM處理器要去Fetch被硬體中斷點設定的記憶體位址指令時,就會觸發這個硬體中斷點,以進行後續的處理程序.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Conditional BreakPoint: 條件式中斷點,可用以設定條件是否滿足,例如像是GDB指令 <strong>‘break xxx if yyy > zzz’</strong>,用以表示當yyy > zzz時,若是執行到xxx位置,就觸發該條件式中斷點,以進行後續的處理程序.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,Temporary Software/Hardware BreakPoint: 暫時性的軟/硬體中斷點,當這中斷點被觸發後,就會失效,而不像是前述的中斷點,可以重複觸發中斷.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
硬體的BreakPoint通常會有數量上的限制(像是Cortex A9支援6個Hardware BreakPoint). 但軟體的BreakPoing,例如透過x86的0xcc (=int 13h=Debug Interrupt),或是使用ARM的Undefined Instruction Exception機制,讓程式碼執行區間的軟體BreakPoint配置,可不受到Hardware BreakPoint數目限制,能依據軟體開發的實際需求,去操作BreakPoint的配置.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
同樣的,Debug Parent也要在收到wait Notification後,確認目前Debug Child Stop的狀態是因為剛才置入的除錯指令或真的是一般性的Undefined Instruction所觸發的(例如: Stack覆蓋或Function Pointer指向錯誤的地址),若是屬於因為置換指令所觸發的軟體BreakPoint,亦可透過把置換掉的指令集內容置換回原本的指令集內容,以便讓Debug Child可以執行原本的指令,就像是沒受到任何影響的執行下去.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考arm-linux-tdep.c中,有關 GDB 支援ARM Linux軟體BreakPoint的Undefined Instruction指令定義如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="807">/* Under ARM GNU/Linux the traditional way of performing a breakpoint is to execute a particular software interrupt, rather than use a particular undefined instruction to provoke a trap. Upon exection of the software interrupt the kernel stops the inferior with a SIGTRAP, and wakes the debugger. */<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const char arm_linux_arm_le_breakpoint[] = { <strong>0x01, 0x00, 0x9f, 0xef </strong>};</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const char arm_linux_arm_be_breakpoint[] = { <strong>0xef, 0x9f, 0x00, 0x01</strong> };</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* However, the EABI syscall interface (new in Nov. 2005) does not look at the operand of the swi if old-ABI compatibility is disabled. Therefore, use an undefined instruction instead. This is supported as of kernel version 2.5.70 (May 2003), so should be a safe assumption for EABI binaries. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const char eabi_linux_arm_le_breakpoint[] = { <strong>0xf0, 0x01, 0xf0, 0xe7</strong> };</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const char eabi_linux_arm_be_breakpoint[] = {<strong> 0xe7, 0xf0, 0x01, 0xf0</strong> };</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* All the kernels which support Thumb support using a specific undefined instruction for the Thumb breakpoint. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const char arm_linux_thumb_be_breakpoint[] = {<strong>0xde, 0x01</strong>};</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const char arm_linux_thumb_le_breakpoint[] = {<strong>0x01, 0xde</strong>};</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* Because the 16-bit Thumb breakpoint is affected by Thumb-2 IT blocks, we must use a length-appropriate breakpoint for 32-bit Thumb instructions. See also thumb_get_next_pc. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const char arm_linux_thumb2_be_breakpoint[] = {<strong> 0xf7, 0xf0, 0xa0, 0x00</strong> };</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const char arm_linux_thumb2_le_breakpoint[] = { <strong>0xf0, 0xf7, 0x00, 0xa0</strong> };</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
更進一步參考 Linux Kernel 3.0.8中的/arch/arm/kernel/ptrace.c ,可以知道在ARMv32或是Thumb Mode下,目前在Linux Kernel中建議的Undefined Instruction如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="807">/*<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* New breakpoints – use an undefined instruction. The ARM architecture</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* reference manual guarantees that the following instruction space</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* will produce an undefined instruction exception on all CPUs:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* ARM: xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* Thumb: 1101 1110 xxxx xxxx</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*/</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define BREAKINST_ARM <strong>0xe7f001f0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define BREAKINST_THUMB <strong>0xde01</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
所支援的ARMv32指令集為ARM EABI所定義的Undefined Instruction指令編碼,並且ARM也確保這些指令編碼可在所有的ARM平台上產生Undefined Instruction Exception,以便相容於不同的ARM處理器方案,使軟體BreakPoint順利運作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
更進一步來看,並非所有的Linux Kernel Undefined Instruction Exception都是跟GDB/Ptrace除錯機制有關,也有很大機會是軟體因為遇到Stack Overflow,或因為軟體邏輯上的缺陷而導致程式執行到錯誤的位置,以致於讀取到錯誤的指令集,也同樣的觸發了Undefined Instruction Exception,也因此Kernel在arch/arm/kernel/traps.c中的函式 asmlinkage void __exception do_undefinstr(struct pt_regs *regs) 中有支援Undefined Hook介面,會在每次進入到Undefined Instruction Exception時會呼叫函式call_undef_hook去確認有哪些核心模組有註冊Undefined Instruction OpCode. 也因為有這樣的Undefined Instruction支援介面存在,其它ARM Linux指令集的模擬,也會透過同樣的介面支援平台上不支援的處理器指令集與行為.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由核心所支援的Undefined Instruction Hook使用前會先透過register_undef_hook進行註冊,所以我們可以檢視在ARM Linux中有哪些部分使用到register_undef_hook,就可以清楚目前到底還有哪些核心機制有使用到Undefined Instruction機制,筆者會在下一段文章中,舉Linux Kernel透過Undefined Instruction Exception以ARMv6之後開始提供的ldrex與strex指令取代SWP/SWPB指令集的例子來說明Linux Kernel對於Undefined Instruction Exception的延伸應用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在透過ptrace撰寫Debug Parent時,另一個重要的課題就是有哪些Debug Client的wait Event可以用來讓Parent判別目前Child的狀態,筆者舉 include/sys/wait.h中的巨集簡要說明如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, WIFEXITED: 用在Debug Parent中,用來判別wait所接收回來的Debug Child狀態,該Debug Client 是不是已經正常執行結束,並可透過 WEXITSTATUS 巨集取得Debug Child的Exit Code.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, WIFSIGNALED: 用在Debug Parent中判別 Debug Child是否因為收到Signal而導致不正常的結束執行,並可透過 WTERMSIG巨集取得Debug Child所收到的Signal號碼(例如:可以故意透過kill(PID,12) 送Signal 12給Debug Child,而在這發生不正常結束的情況下,就可以透過WTERMSIG由wait確認最後Debug Child所收到的Signal為12.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, WIFSTOPPED:用在Debug Parent中判別 Debug Child是否因為收到Signal而導致執行暫停,一般來說為 SIGTRAP (Trace trap),也就是Signal 5. 可透過WSTOPSIG巨集取得Debug Child所收到導致執行暫停的Signal號碼.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4, WIFCONTINUED:用在Debug Parent中判別 Debug Child是否收到Signal SIGCONT以繼續執行下去.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Linux Kernel 支援的Ptrace命令, 包括在kernel/ptrace.c 所實作跟平台無關,或在arch/arm/kernel/ptrace.c所實作跟ARM處理器平台有關Ptrace Command的列表可參考以下介紹</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">Ptrace 命令</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_TRACEME</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以通知應用程式被它的Parent Process進行除錯,除了SIGKILL以外的Signal都會被送給這個除錯中的Process,並會導致該被除錯的Process Stop,如果Debug Parent這時有透過wait函式等待的話,這時Debug Parent就會收到通知的訊息.一般來說Debug Parent會收到 SIGTRAP(Signal 5),用以暫停Debug Child,並讓Debug Parent可以去設定相關的BreakPoint/WatchPoint,確認當下的除錯狀況等等. 在Debug Parent確認所預備的環境無誤後,就可以透過SIGCONT讓Debug Child繼續執行下去.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以參考如下實作範例,會由Parent process fork出一個Child Process,並由Parent Process下達Continue指令同意Child Process可以往後繼續執行.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#include <sys/ptrace.h></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#include <unistd.h></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#include <stdio.h></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>int main()</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>{</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>int pid;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>if((pid = fork()) == 0) {</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>ptrace(PTRACE_TRACEME, 0, 0, 0);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>printf(“In Child, In Child, try to call ls command.\n”);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>execl(“/bin/ls”, “”, 0);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>} else {</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>//Child is under Stop-State now.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>printf(“In Parent,Stop…5 second.\n”);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>sleep(5);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>printf(“Continue the Child process.\n”);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>ptrace(PTRACE_CONT, pid, 0, 0);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>return 0;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行結果為</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>In Parent,Stop…5 second.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>In Child, call the outside command.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Continue the Child process.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA GroupA.txt test test3.c test5 TestA.A TestA.txt</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA.asm GroupB test2 test4 test5.c TestA.asm TestB.c</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA.c GroupB.c test2.c test4.c TestA TestA.c test.c</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>[root@localhost test]#</strong></div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_KILL</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以送出SIGKILL給Debug Child,並使其結束執行.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
child->exit_code = SIGKILL;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
wake_up_state(child, __TASK_TRACED);</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SETOPTIONS</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以透過ptrace_setoptions函式設定ptrace debug child的Option參數,可以選擇包括PT_TRACESYSGOOD,PT_TRACE_FORK,PT_TRACE_VFORK,PT_TRACE_CLONE,PT_TRACE_EXEC,PT_TRACE_VFORK_DONE,PT_TRACE_EXIT.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(since Linux 2.4.6; see BUGS for caveats)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可用以設定Debug Parent執行ptrace時的除錯選項,每個選項都會對應到一個Bit Mask,目前支援以下選項</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,PTRACE_O_TRACESYSGOOD (since Linux 2.4.6):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可設定PTRACE_O_TRACESYSGOOD 讓Debug Child在Stop狀態時,由Debug Parent判斷SIGTRAP 的bit 7是否為1,若為真就是透過System Call所導致的System Call Trap,可用以監控Debug Child所有呼叫的System Call行為. (例如 strace指令的實作一樣),如下範例程式.</div>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px;"><tbody>
<tr><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">#include <stdio.h><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <string.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <errno.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <unistd.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <signal.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <sys/ptrace.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <sys/user.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <sys/reg.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/*</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* syscall names for i386 under 2.5.51, taken from <asm/unistd.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*/</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char *(syscall_names[256]) = {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“exit”, “fork”, “read”, “write”, “open”, “close”, “waitpid”, “creat”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“link”, “unlink”, “execve”, “chdir”, “time”, “mknod”, “chmod”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“lchown”, “break”, “oldstat”, “lseek”, “getpid”, “mount”, “umount”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“setuid”, “getuid”, “stime”, “ptrace”, “alarm”, “oldfstat”, “pause”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“utime”, “stty”, “gtty”, “access”, “nice”, “ftime”, “sync”, “kill”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“rename”, “mkdir”, “rmdir”, “dup”, “pipe”, “times”, “prof”, “brk”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“setgid”, “getgid”, “signal”, “geteuid”, “getegid”, “acct”, “umount2″,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“lock”, “ioctl”, “fcntl”, “mpx”, “setpgid”, “ulimit”, “oldolduname”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“umask”, “chroot”, “ustat”, “dup2″, “getppid”, “getpgrp”, “setsid”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“sigaction”, “sgetmask”, “ssetmask”, “setreuid”, “setregid”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“sigsuspend”, “sigpending”, “sethostname”, “setrlimit”, “getrlimit”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“getrusage”, “gettimeofday”, “settimeofday”, “getgroups”, “setgroups”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“select”, “symlink”, “oldlstat”, “readlink”, “uselib”, “swapon”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“reboot”, “readdir”, “mmap”, “munmap”, “truncate”, “ftruncate”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“fchmod”, “fchown”, “getpriority”, “setpriority”, “profil”, “statfs”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“fstatfs”, “ioperm”, “socketcall”, “syslog”, “setitimer”, “getitimer”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“stat”, “lstat”, “fstat”, “olduname”, “iopl”, “vhangup”, “idle”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“vm86old”, “wait4″, “swapoff”, “sysinfo”, “ipc”, “fsync”, “sigreturn”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“clone”, “setdomainname”, “uname”, “modify_ldt”, “adjtimex”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“mprotect”, “sigprocmask”, “create_module”, “init_module”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“delete_module”, “get_kernel_syms”, “quotactl”, “getpgid”, “fchdir”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“bdflush”, “sysfs”, “personality”, “afs_syscall”, “setfsuid”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“setfsgid”, “_llseek”, “getdents”, “_newselect”, “flock”, “msync”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“readv”, “writev”, “getsid”, “fdatasync”, “_sysctl”, “mlock”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“munlock”, “mlockall”, “munlockall”, “sched_setparam”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“sched_getparam”, “sched_setscheduler”, “sched_getscheduler”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“sched_yield”, “sched_get_priority_max”, “sched_get_priority_min”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“sched_rr_get_interval”, “nanosleep”, “mremap”, “setresuid”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“getresuid”, “vm86″, “query_module”, “poll”, “nfsservctl”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“setresgid”, “getresgid”, “prctl”,”rt_sigreturn”,”rt_sigaction”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“rt_sigprocmask”, “rt_sigpending”, “rt_sigtimedwait”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“rt_sigqueueinfo”, “rt_sigsuspend”, “pread”, “pwrite”, “chown”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“getcwd”, “capget”, “capset”, “sigaltstack”, “sendfile”, “getpmsg”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“putpmsg”, “vfork”, “ugetrlimit”, “mmap2″, “truncate64″,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“ftruncate64″, “stat64″, “lstat64″, “fstat64″, “lchown32″, “getuid32″,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“getgid32″, “geteuid32″, “getegid32″, “setreuid32″, “setregid32″,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“getgroups32″, “setgroups32″, “fchown32″, “setresuid32″,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“getresuid32″, “setresgid32″, “getresgid32″, “chown32″, “setuid32″,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“setgid32″, “setfsuid32″, “setfsgid32″, “pivot_root”, “mincore”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“madvise”, “getdents64″, “fcntl64″, 0, “security”, “gettid”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“readahead”, “setxattr”, “lsetxattr”, “fsetxattr”, “getxattr”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“lgetxattr”, “fgetxattr”, “listxattr”, “llistxattr”, “flistxattr”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“removexattr”, “lremovexattr”, “fremovexattr”, “tkill”, “sendfile64″,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“futex”, “sched_setaffinity”, “sched_getaffinity”, “set_thread_area”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“get_thread_area”, “io_setup”, “io_destroy”, “io_getevents”, “io_submit”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“io_cancel”, “fadvise64″, 0, “exit_group”, “lookup_dcookie”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vPid;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vGetChildStatus;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_regs_struct u_in;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if((vPid = fork()) == 0) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(PTRACE_TRACEME, 0, 0, 0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“In Child, try to call /bin/ls command.\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
execl(“/bin/ls”, “”, 0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} else {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
wait(0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(PTRACE_SETOPTIONS, vPid, 0, PTRACE_O_TRACESYSGOOD);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(PTRACE_SYSCALL, vPid, 0,0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
while(1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{//Busy 1 Loop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Wait for Child to Stop at Next Inst.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(wait(&vGetChildStatus)==-1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Failed to wait.\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (WIFSTOPPED(vGetChildStatus))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{//Child is under Stop-Stat.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if((WSTOPSIG(vGetChildStatus)&0x80)==0)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Not caused by a syscall\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(PTRACE_GETREGS, vPid, 0, &u_in);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“System Call(StopSig:%xh):%s %ld\n”,WSTOPSIG(vGetChildStatus),syscall_names[u_in.orig_rax],u_in.orig_rax);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(PTRACE_SYSCALL, vPid, 0,0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else if (WIFEXITED(vGetChildStatus))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Child exited with status %d\n”,WEXITSTATUS(vGetChildStatus));</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (WIFSIGNALED(vGetChildStatus))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Child was terminated by signal %d. “,WTERMSIG(vGetChildStatus));</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}//End of Busy 1 Loop</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,PTRACE_O_TRACEFORK (since Linux 2.5.46):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可支援在Debug Child中呼叫到fork時,觸發SIGTRAP暫停Debug Child執行,並讓Debug Parent可以收到 (SIGTRAP | PTRACE_EVENT_FORK << 8)的Notification.而fork所新產生的Process也會進入被除錯的模式中,並在新的Process開始執行後,便隨著產生 SIGSTOP,讓新的Process暫停執行.對於Debug Parent Process來說,則可以透過 PTRACE_GETEVENTMSG命令取得這個新產生的Process Id.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,PTRACE_O_TRACEVFORK (since Linux 2.5.46):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可支援在Debug Child中呼叫到 vfork時,觸發SIGTRAP暫停Debug Child執行,並讓Debug Parent可以收到 (SIGTRAP | PTRACE_EVENT_VFORK << 8 )的Notification.而vfork所新產生的Process也會進入被除錯的模式中,並在新的Process開始執行後,便隨著產生 SIGSTOP,讓新的Process暫停執行.對於Debug Parent Process來說,則可以透過 PTRACE_GETEVENTMSG命令取得這個新產生的Process Id.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4, PTRACE_O_TRACECLONE (since Linux 2.5.46):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可支援在Debug Child中呼叫到clone時,觸發SIGTRAP暫停Debug Child執行,並讓Debug Parent可以收到 (SIGTRAP |PTRACE_EVENT_CLONE << 8 )的Notification.而clone所新產生的Process也會進入被除錯的模式中,並在新的Process開始執行後,便隨著產生 SIGSTOP,讓新的Process暫停執行.對於Debug Parent Process來說,則可以透過 PTRACE_GETEVENTMSG命令取得這個新產生的Process Id.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,PTRACE_O_TRACEEXEC (since Linux 2.5.46):</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可支援在Debug Child中呼叫到execve時,觸發SIGTRAP暫停Debug Child執行,並讓Debug Parent可以收到 (SIGTRAP |PTRACE_EVENT_EXEC << 8)的Notification.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,PTRACE_O_TRACEVFORKDONE (since Linux 2.5.60)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可支援在Debug Child中呼叫vfork結束後,觸發SIGTRAP暫停Debug Child執行,並讓Debug Parent可以收到 (SIGTRAP | PTRACE_EVENT_VFORK_DONE << 8)的Notification.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7, PTRACE_O_TRACEEXIT (since Linux 2.5.60)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會在Debug Child結束執行時進行暫停,並觸發SIGTRAP暫停Debug Child執行,並讓Debug Parent可以收到 (SIGTRAP | PTRACE_EVENT_EXIT << 8)的Notification.由於是在Debug Child結束執行時進行暫停,所以有關的暫存器與記憶體內容都還是可以正確的讀取.對於Debug Parent Process來說,則可以透過 PTRACE_GETEVENTMSG命令取得Debug Child的Exit Status.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_CONT</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">重啟執行處於Stop狀態的Process,會透過函式ptrace_resume,由Debug Parent對Debug Child執行Continue的動作,讓Debug Child能繼續執行.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_PEEKTEXT, PTRACE_PEEKDATA</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以讀取指定的Debug Child記憶體空間的資料內容,可一次傳回32bits,PTRACE_PEEKTEXT與PTRACE_PEEKDATA原意上是要分別取得屬於程式碼的Text與資料節區的Data,但Linux本身並沒有把這兩塊的記憶體空間各自獨立,因此使用者只需指定所需讀取的記憶體位址,就可以依序把兩者資料讀取回來.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於透過這機制讀取記憶體內容的效率較差,因此也可以看到在GDB中會改以透過/proc/%d/mem的機制,以檔案系統Shared Memory File Mapping機制進行效率較高的讀取動作.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_POKETEXT, PTRACE_POKEDATA</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以把數值內容寫入到Debug Child的記憶體空間,如上所述,使用者只需指定所需寫入的記憶體位址,就可以依序對Debug Child的記憶體空間進行寫入的動作.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_PEEKUSER</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以讀取Debug Child的User Data,所讀取的資料在32-bits Linux環境下會以32-bits Alignment的方式排列,主要包括當下Debug Child的暫存器與跟Process有關的資訊,參考x86 Linux環境下的sys/user.h可知在x86平台上,這資訊包括<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_regs_struct regs;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int u_fpvalid;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_fpregs_struct i387;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long int u_tsize;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long int u_dsize;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long int u_ssize;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long start_code;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long start_stack;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
long int signal;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int reserved;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_regs_struct* u_ar0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_fpregs_struct* u_fpstate;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long int magic;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char u_comm [32];</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long int u_debugreg [8];</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或像是在筆者ARM Linux編譯器的環境中,這資訊包括</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_regs regs; /* General registers */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int u_fpvalid; /* True if math co-processor being used. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long int u_tsize; /* Text segment size (pages). */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long int u_dsize; /* Data segment size (pages). */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long int u_ssize; /* Stack segment size (pages). */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long start_code; /* Starting virtual address of text. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long start_stack; /* Starting virtual address of stack. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
long int signal; /* Signal that caused the core dump. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int reserved; /* No longer used */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_regs *u_ar0; /* help gdb to find the general registers. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long magic; /* uniquely identify a core file */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char u_comm[32]; /* User command that was responsible */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int u_debugreg[8];</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_fpregs u_fp; /* Floating point registers */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct user_fpregs *u_fp0; /* help gdb to find the FP registers. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_POKEUSER</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以把數值回寫到Debug Child的User Data,所寫入的資料在32-bits Linux環境下,會是 32-bits Alignment.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_GETEVENTMSG</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以讓Debug Parent可獲取剛才發生的ptrace Event,可由Debug Parent呼叫put_user(child->ptrace_message, datalp)取得.如果Debug Parent透過wait notification 所取得的Event (event = (Nitification >> 16) & 0xffff;),等於PTRACE_EVENT_FORK, PTRACE_EVENT_VFORK 或PTRACE_EVENT_CLONE,則可以透過PTRACE_GETEVENTMSG取得新Process的ID,若該Event等於PTRACE_EVENT_EXIT,則可以透過PTRACE_GETEVENTMSG取得新Debug Child的Exit Status.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_ATTACH</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">主要用以針對已經執行的Process進行除錯,例如,可指定Process Id並執行<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(PTRACE_ATTACH, vPID,0,0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就可以使一個Process成為一個被除錯的Debug Child Process,並會讓這個被除錯的Process就像是透過執行 PTRACE_TRACEME的Process一樣,由呼叫端成為它的Debug Parent Process,可以透過wait函式收到來自Debug Child Process的Notification(以進行就像是PTRACE_TRACEME一樣的除錯流程).雖然彼此有Debug Parent/Child的架構在,但Debug Child Process透過getppid時,還是會得到原本的Parent Process ID.</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_DETACH</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">主要用以把被Attach成為Debug Child Process的行程,進行Detach的動作,例如,可帶入目前成為Debug Child Process的ID,並執行<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace(PTRACE_DETACH,vPID,0,0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可針對的Process Id包括</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,透過Fork與PTRACE_TRACEME命令的行程</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,或是正在運作的行程藉由PTRACE_ATTCH接上成為Debug Child Process</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
都可以透過這個命令,讓被除錯的行程可以脫離除錯的狀態,一路執行下去</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SETSIGINFO</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以把Debug Parent的 siginfo_t structure複製到Debug Child的行程記憶體空間中.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_GETSIGINFO</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">把Debug Child行程記憶體空間中的siginfo_t structure複製到Debug Parent的行程記憶體中.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SYSC<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ALL, PTRACE_SINGLESTEP</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">這兩個命令主要用以把Debug Child從Stop狀態重新往後執行,但基於PTRACE_SINGLESTEP的命令會在執行下個指令時讓Debug Child重新進入Stop狀態,也就是說如果我們希望Debug Child執行每一個ARM指令時,都會觸發SIGTRAP,讓Debug Parent可以有機會檢視執行狀態以進行調整的話,就可以使用這個ptrace 命令.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
反之,PTRACE_SYSCALL命令則會在System Call呼叫前先觸發SIGTRAP,讓Debug Parent可以檢視Debug Child呼叫該System Call時所帶入的變數.並在該System Call呼叫結束時觸發第二次的SIGTRAP,讓Debug Parent取得Debug Child執行System Call的返回值.離開時觸發該Event.也就是說對於PTRACE_SYSCALL命令來說,每個System Call呼叫都會觸發兩次SIGTRAP,一個是在呼叫前,一個是在呼叫後.基於這樣的使用行為,其實我們也可以很容易的去撰寫自己的System Call Trace工具.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SYSEMU, PTRACE_SYSEMU_SINGLESTEP</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">主要用在像是User-Mode Linux這樣的環境中,以PTRACE_SYSEMU來說,會模擬System Call的呼叫,但並不會真的去執行Native Linux Kernel的System Call,而是會讓Debug Parent去執行出對應的System Call行為.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而PTRACE_SYSEMU_SINGLESTEP也是類似的目的,只是這個命令模擬的是PTRACE_SINGLESTEP單步執行的行為. 這兩個特別的ptrace命令主要用來讓應用可以模擬User-Space Linux Kernel環境的執行,若各位開發上有此需求,可以進一步的加以深究.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PT_GETFPREGS</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以取得Debug Child所在處理器(例如:ARM)的 Floating Point暫存器</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SETFPREGS</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以修改Debug Child所在處理器(例如:ARM) Floating Point暫存器值</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_GETREGS, PTRACE_GETFPREGS</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以取得Debug Child所在處理器(例如:ARM) 一般暫存器值</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SETREGS, PTRACE_SETFPREGS</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以修改Debug Child所在處理器(例如:ARM) 一般暫存器值</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_GETWMMXREGS</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以取得Debug Child所在處理器(例如:ARM) WMMX暫存器值</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SETWMMXREGS</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以修改Debug Child所在處理器(例如:ARM) WMMX暫存器值</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_GETVFPREGS</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以取得Debug Child所在處理器(例如:ARM) VFP暫存器值</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SETVFPREGS</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以修改Debug Child所在處理器(例如:ARM)VFP暫存器值</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_GET_THREAD_AREA</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">Fetch the thread-local storage pointer for libthread_db</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_GETHBPREGS</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以透過Linux Kernel ptrace System Call來取得屬於平台相關的 Hardware Breakpoing與Watchpoint資訊</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="153">PTRACE_SETHBPREGS</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="656">用以透過Linux Kernel ptrace System Call來設定屬於平台相關的 Hardware Breakpoing與Watchpoint.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以上介紹了Ptrace的命令,行為以及軟體BreakPoint的概念,接下來重要的議題就是由ARM支援的Hardware BreakPoints 與 WatchPoints (可參考網頁資訊<a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0446d/BEICGIFG.html" style="color: #cc0000; font-weight: bold;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0446d/BEICGIFG.html</a> ). ARM上的硬體BreakPoints與WatchPoints會偵測指令的Fetch與資料Access動作,當條件滿足時,就會讓處理器進入Debug State.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
硬體的BreakPoint 可讓開發者設定ARM執行到特定的記憶體位址時,中斷處理器的執行,以便進行除錯分析的工作.而硬體的WatchPoint 主要用以讓開發者能監控ARM去存取特定資料的記憶體位址時,可觸發中斷點,讓開發者可以找出在開發過程中所遇到的變數污染問題,或是可以透過設定變數的條件式,在指定的變數滿足該條件時 (例如, gCount>100)觸發WatchPoint中斷,以便開發者可以找出程式設計資料處理邏輯上的問題.一般來說WatchPoints可以分為以下幾類</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,當指定的記憶體位址資料倍存取時,就會觸發WatchPoints.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,當指定的記憶體位址資料滿足條件時,,就會觸發WatchPoints.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在基於MMU的環境下,ARM的硬體BreakPoint/WatchPoint都是依據Virtual Address虛擬地址來做配置的,也因為在有MMU的多工環境下,每個Process都會各自擁有屬於自己的虛擬地址空間,因此雖然硬體BreakPoint/WatchPoint都是依據虛擬地址來做配置,但ARM可透過把BreakPoint 4與BreakPoint 5拿來當做Context Id使用,也就是說讓虛擬位址空間的BreakPoint/WatchPoint可以綁定一個Context Id(例如:對應到 Process ID),藉此就可以讓硬體BreakPoint/WatchPoint的配置是一個虛擬位址空間加上一個Context ID.可支援多工環境下,針對虛擬位址空間所配置的硬體BreakPoint/WatchPoint會在錯誤的Process空間觸發的問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於一般區域變數是放在Stack中,而且若不在該執行函式的Scope內,也無法使用該區域變數,因此ARM硬體的WatchPoint只能支援Global與Static變數的Symbol,因為這兩者所在的Symbol記憶體位址在載入後就會確定下來,沒有執行Scope的問題.但若是開發者已經知道哪一塊記憶體要透過WatchPoint監看,透過鎖定記憶體的方式操作也是可以的.此外,由於ARM處理器PipeLine的行為影響,有機會導致硬體WatchPoint觸發時,其實當下的PC暫存器的記憶體位址並非去修改該變數的真正指令記憶體位址,此時還是會需要開發者根據當下的指令集執行狀態判斷,給予正確的分析.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Linux上透過Ptrace提供的PTRACE_GETHBPREGS/PTRACE_SETHBPREGS命令,就能透過對ARM CoProcessor 14的設定,使用ARM上運作的Linux GDB能支援Hardware BreakPoint/WatchPoint .硬體的BreakPoints與WatchPoints可讓ARM硬體在特定的Event或條件觸發時暫停執行,以便讓開發者可以檢視記憶體,暫存器,變數內容,或採取任何可幫助除錯的動作,之後則讓程式繼續執行以觸發所設定的相關除錯條件.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以既有的ARM架構來說,ARM926支援兩個Hardware WatchPoint,兩者可依需求定義為用以偵測指令Fetch到特定位址觸發的BreakPoint(for Instruction Fetch),或用以偵測資料存取特定位址變數而進行觸發的WatchPoint(for Data Access).而像是 ARM1176則支援6個Hardware BreakPoint,2個Hardware WatchPoint. Cortex M3則支援6個Hardware BreakPoint與4個Hardware WatchPoint .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而除了前面提到的軟體中斷透過Undefined Instruction Exception實現外,在ARMv5架構之後,也支援新的ARM指令集 “BKPT (Breakpoint)”,可用以透過置入該指令的方式,增加Software BreakPoint的個數,解決Hardware BreakPoint個數限制的問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後,用下面的圖示,簡單呈現Debug Parent兩種接上Debug Child的機制,以及在Debug流程結束後,兩種結束Debug Child除錯狀態的方式.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWJr9F7pWWS9YquxX_qW4yXawGSptOlcdMnuxdA8_dEO4kZReBgSRLvvdeejr0VFWm5Iw2O3kOJhNjahKKzzOGWWqVAQjm_zN_l0bBWmQL9Fb4ZjQaGGm3J-MVfY-pGdJkyJWIHOk_Uxo/s1600/image004%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="430" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWJr9F7pWWS9YquxX_qW4yXawGSptOlcdMnuxdA8_dEO4kZReBgSRLvvdeejr0VFWm5Iw2O3kOJhNjahKKzzOGWWqVAQjm_zN_l0bBWmQL9Fb4ZjQaGGm3J-MVfY-pGdJkyJWIHOk_Uxo/s1600/image004%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<h1 id="15582_arm-%e7%a1%ac%e9%ab%_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
ARM 硬體 BreakPoint/WatchPoint</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考ARM文件”Cortex-A9 Technical Reference Manual”,每個硬體的BreakPoint操作都有兩個配對的暫存器,例如BVR0(Breakpoint Value Register #0)與BCR0(Rreakpoint Control Register #0),並依序到BVR4與BCR4,BVR5與BCR5. 而儲存在Breakpoint Value Register中的值可以為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,一個指令所在的虛擬記憶體位址 (IVA,Instruction Virtual Address)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,一個Process Context ID</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,一對指令所在的虛擬記憶體位址(IVA )與Process Context ID 的組合 (需要有兩個BVR配對使用)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果希望鎖定特定Process Id的虛擬記憶體空間進行除錯配置,就必須要有一個BVR0-BVR3的BVR搭配一個BVR4或BVR5作為Context Id,也就是說要有兩個BVR暫存器成對,前者用來指定虛擬記憶體空間指令執行所在的記憶體位址,後者用來指定所要鎖定的Context ID (Process ID+ASPD),Context Id的32-bits組成為 Process ID[31:8] + ADID [7:0], Process Id為目前系統給當前執行Process唯一的識別碼,可用以讓Trace/Debug Logic識別目前正在執行的Process.而ASID (Address Space Identifier)而對應到目前Process所在的記憶體空間識別碼,主要是供Memory Management有關的識別之用.一旦有指定Context ID,在執行階段就會依據 CP15 Context ID Register(c13)與Instruction Address Bus的內容進行觸發的依據.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以目前的Cortex A9來說,只有BPR4與BPR5可以使用BVR4與BVR5來當做Context Id的使用,換句話說,如果要考慮到支援應用程式Process Id層級的BreakPoint除錯機制,那硬體的BreakPoint最多就只能同時允許對兩個應用程式的使用者空間使用BVR4與BVR5進行Context ID設定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從ARM針對這Feature的支援來看,Context Id是在ARMv6的架構之後才支援的機制,其中ASID是用以識別系統每個執行行程的虛擬記憶體空間唯一個識別碼 .而ASID還可用以Tag處理器的Cache/TLB Entry. Context Id對於硬體支援的Debugger/Trace Logic可供識別系統目前Process執行的資訊,且這個ID必須要是整個系統中唯一的識別碼.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考cpu_v7_switch_mm的實作 (in arch/arm/mm/proc-v7.S),在進行Context-Switch時,會透過CoProcess 15 c13的命令,把Context Id設定為0 (=r2),</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mcr p15, 0, r2, c13, c0, 1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
隨後設定新Process的Page Table Entry給TTBR0,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mcr p15, 0, r0, c2, c0, 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後才把最新Process的 Context Id (=r1)透過CoProcess 15 c13命令進行設定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mcr p15, 0, r1, c13, c0, 1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果沒有指定Context ID,該BVR的虛擬記憶體位址執行BreakPoint觸發就無針對特定行程的記憶體空間進行虛擬位址的BreakPoint除錯機制,但實際上由於是藉由Undefined Instruction Exception來實現這機制,以目前Linux Kernel對Context Id的處理來說,ASID是透過cpu_last_asid (in arch/arm/mm/context.c)進行配置, cpu_last_asid初值為ASID_FIRST_VERSION (=0x100)會從0x100依序遞增為0x101,0x102..並往上持續累加到0xffffffff,最後為0,然後又從0x100開始累加,也就是說對硬體而言ASID只有8 its,但對Linux Kernel而言CoProcess 15的Context Id以其32bits長度來看,足以充分的表示Context bits Process id + 8bits ASID組合所代表的意義,能確保Context Id在系統中的唯一性. 但這樣的實作,其實與ARM 原本對於Context Id設計的本意是不一樣的.例如參考ARM的文件,Context Id中的Process Id應該要對應到作業系統中唯一的Process ID,但根據目前Linux Kernel的實作,Context Id會等於cpu_last_asid隨著應用程式產生的累加值,而跟實際的Process Id對應兩者是拖勾的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其實,對於核心來說,只要記得哪個Process有設定BreakPoint,並記住它使用的BreakPoint資訊,一旦在特定的記憶體位址中觸發BreakPoint,就可以透過Kernel所記住的這些BreakPoint與Task之間的關係,更直接一點來說,就是透過核心所記錄的相關Task BreakPoint資訊,用軟體手段達到使用者端虛擬記憶體與對應執行Task行程的關聯BreakPoint觸發行為.從效率而言,當然是透過硬體BreakPoint的效率最高,但以對所有ARM處理器(ARMv5或以前沒有支援ARM Context Id的處理器)來說,用核心Undefined Instruction Exception的操作,可以讓BreakPoint個數沒有上限,又能不被ARM處理器世代的差異而限制住實作彈性與平台支援的豐富性.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
相對的,如果沒有Context ID的話,硬體 BreakPoint就無法針對特定Process ID所屬的Virtual Address進行執行,的指令集BreakPoint使用,這也是因為屬於Kernel Space的區塊,在Linux Kernel中,可以確保不管上層的應用程式如何切換,大家所共用的Kernel Space虛擬記憶體空間都是一致的,而在面對多工的環境下,會有不同的Process彼此切換與Context Id的變動,也因此如果要特別指定在特別的應用程式下的特別的記憶體位址的硬體BreakPoints功能有效的發揮作用,既需要透過成對的硬體BreakPoint Value Registers,讓其中一個暫存器指定Instruction Virtual Address而另一個暫存器用以指定Context ID(也就是等於當下執行或指定要設定硬體BreakPoint的Process ID),基於 IVA與Context Id所Link起來的硬體BreakPoint條件,就會在IVA與CP15中的Context Id與我們指定的BreakPoint Context Id兩個條件都滿足時,透過ARM處理器觸發Debug Event以進行後續的除錯流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從cpu_last_asid與對CP15 Context Id的配置來看,我們可以知道雖然ARMv6之後對Context Id的設計為Process ID+ ASID所搭配的32-bits組合,但在目前的ARM Linux Kernel中,並沒有如此的實現,ASID仍舊會隨著應用程式的載入與消滅而隨次遞增,每一次都會有所差異,而在超過0xff 之後的數值就會往Process Id的部份遞增,例如會累計至 0x101,0x400..etc,也就是說對ASID原本的用意來說也並沒有違背,只是Linux Kernel變成會依據應用程式載入的先後順序來做ASID的累加動作,就算Process Id跟Linux Kernel上真正的Peocess Id不是真正的對應,但卻也不影響ASID對TLB/Cache所能發揮的影響. 畢竟,都隨著應用程式的產生而累加了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示為參考自 ”Cortex-A9 Technical Reference Manual”的BVR暫存器說明</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="808">Breakpoint Value Registers</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">Bits</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Description</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[31:0]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Breakpoint value. The reset value is 0.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下則為BCR暫存器的說明(SBZP= Should-Be-Zero-or-Preserved on Writes, RAZ=Appear as Zero on Reads).</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="808">Breakpoint Control Register</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">Bits</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Description</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[31:29]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ on reads, SBZP on writes.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[28:24]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Breakpoint address mask.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
RAZ/WI</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b00000 = no mask</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[23]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ on reads, SBZP on writes.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[22:20]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Meaning of BVR:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b000 = instruction virtual address match</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b001 = linked instruction virtual address match</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b010 = unlinked context ID</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b011 = linked context ID</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b100 = instruction virtual address mismatch</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b101 = linked instruction virtual address mismatch</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b11x = reserved.s</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[19:16]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Linked BRP number. The binary number encoded here indicates another BRP to link this one with.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[15:14]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Secure state access control. This field enables the breakpoint to be conditional on the<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
security state of the processor.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b00 = breakpoint matches in both Secure and Non-secure state</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b01 = breakpoint only matches in Non-secure state</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b10 = breakpoint only matches in Secure state</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b11 = reserved.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[13:9]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ on reads, SBZP on writes.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[8:5]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Byte address select. For breakpoints programmed to match an IVA, you must write a<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
word-aligned address to the BVR. You can then use this field to program the breakpoint so</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
it hits only if you access certain byte addresses.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
If you program the BRP for IVA match:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b0000 = the breakpoint never hits</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b0011 = the breakpoint hits if any of the two bytes starting at address BVR & 0xFFFFFFFC +0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
is accessed</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b1100 = the breakpoint hits if any of the two bytes starting at address BVR & 0xFFFFFFFC +2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
is accessed</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b1111 = the breakpoint hits if any of the four bytes starting at address BVR & 0xFFFFFFFC +0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
is accessed.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
If you program the BRP for IVA mismatch, the breakpoint hits where the corresponding IVA</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
breakpoint does not hit, that is, the range of addresses covered by an IVA mismatch</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
breakpoint is the negative image of the corresponding IVA breakpoint.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
If you program the BRP for context ID comparison, this field must be set to b1111.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Otherwise, breakpoint and watchpoint debug events might not be generated as expected.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[4:3]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ on reads, SBZP on writes.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[2:1]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Supervisor access control. The breakpoint can be conditioned on the mode of the processor.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b00 = User, System, or Supervisor</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b01 = privileged</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b10 = User</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b11 = any.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[0]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Breakpoint enable:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0 = breakpoint disabled, reset value</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 = breakpoint enabled.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以cortex A9為例來說,WatchPoints的操作會有兩個配對的暫存器,主要為WVR(Watchpoint Value Register)與WCR(Watchpoint Control Register),每個硬體WatchPoint操作都需要對應配對的WVRn與WCRn. WVR中會儲存所要監控的資料基於MMU的虛擬記憶體位置DVA(Data Virtual Address). 在多工的環境下,也可以是一個DVA與 Context Id(可以為BVR 4或BVR5)的配對,當所在的Context ID與 DVA都吻合,也就是在多工環境下指定的Process被切換到執行,且去存取該Process記憶體空間對應的DVA虛擬記憶體位址資料時,才會觸發Debug Event.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下則為WVR暫存器的說明</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="808">Watchpoint Value Registers</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">Bits</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Description</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[31:2]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Watchpoint address</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[1:0]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ on reads, SBZP on writes</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下則為WCR暫存器的說明</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="808">Watchpoint Control Register</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">Bits</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Description</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[31:29]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ on reads, SBZP on writes.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[28:24]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Watchpoint address mask.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[23:21]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ on reads, SBZP on writes.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[20]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Enable linking bit:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0 = linking disabled</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 = linking enabled.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
When this bit is set, this watchpoint is linked with the context ID holding BRP selected by the</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
linked BRP field.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[19:16]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Linked BRP number. The binary number encoded here indicates a context ID holding BRP to<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
link this WRP with. If this WRP is linked to a BRP that is not configured for linked context</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ID matching, it is Unpredictable whether a watchpoint debug event is generated</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[15:14]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Secure state access control. This field enables the watchpoint to be conditioned on the security<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
state of the processor.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b00 = watchpoint matches in both Secure and Non-secure state</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b01 = watchpoint only matches in Non-secure state</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b10 = watchpoint only matches in Secure state</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b11 = reserved.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[13]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ on reads, SBZP on writes.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[12:9]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">RAZ/WI</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[8:5]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Byte address select. The WVR is programmed with word-aligned address. You can use this<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
field to program the watchpoint so it only hits if certain byte addresses are accessed.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[4:3]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Load/store access. The watchpoint can be conditioned to the type of access being done.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b00 = reserved</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b01 = load, load exclusive, or swap</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b10 = store, store exclusive or swap</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b11 = either.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SWP and SWPB trigger a watchpoint on b01, b10, or b11. A load exclusive instruction triggers</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
a watchpoint on b01 or b11. A store exclusive instruction triggers a watchpoint on b10 or b11</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
only if it passes the local monitor within the processor</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[2:1]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Privileged access control. The watchpoint can be conditioned to the privilege of the access<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
being done:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b00 = reserved</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b01 = privileged, match if the processor does a privileged access to memory</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b10 = User, match only on nonprivileged accesses</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b11 = either, match all accesses.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="243">[0]</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="565">Watchpoint enable:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0 = watchpoint disabled, reset value</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 = watchpoint enabled.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考arch/arm/include/asm/hw_breakpoint.h,有關struct arch_hw_breakpoint_ctrl ctrl 的結構定義如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">struct arch_hw_breakpoint_ctrl {<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
u32 __reserved : 9,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mismatch : 1,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
: 9,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
len : 8,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
type : 2,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
privilege : 2,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
enabled : 1;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以知道除了Enable/Disable,Privileged access control,Read/Write Type,Byte address select與Mismatch外, 在ARMv6與ARMv7中 BreakPoint有關 Context Id配置與Link/UnLink Context Id的機制並沒有在Linux Kernel中被完全的實現.因此,有關ARMv6與ARMv7的BreakPoint/WatchPoint透過Context Id硬體支援BreakPoint/WatchPoint,並不包含在筆者Linux Kernel 3.0.8的環境中,但基於Undefined Instruction Exception與Kernel對Process Id的紀錄,Linux Kernel所支援的Ptrace對特定應用程式的資料WatchPoint與指令BreakPoint操作上並不受影響.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,為Linux Kernel初始化Control Register的部份代碼.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static inline u32 encode_ctrl_reg(struct arch_hw_breakpoint_ctrl ctrl)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return (ctrl.mismatch << 22) | (ctrl.len << 5) | (ctrl.type << 3) |</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(ctrl.privilege << 1) | ctrl.enabled;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來簡要說明,GDB是如何透過 ptrace的PTRACE_GETHBPREGS/PTRACE_SETHBPREGS去設定硬體的BreakPoints與WatchPoint,參考Linux Kernel 3.0.8 中的Source Code arch/arm/kernel/ptrace.c,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
long arch_ptrace(struct task_struct *child, long request,unsigned long addr, unsigned long data)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
統一的路口為 kernel/ptrace.c,然後會透過函式arch_ptrace呼叫進入arch/arm/kernel/ptrace.c中,有關屬於Linux在ARM平台上的ptrace實作. 在 kernel/ptrace.c中的ptrace函式,為Linux Kernel提供給上層應用程式ptrace System Call的實作介面,如下所示,也可以看到在這的ptrace函式中會再呼叫進入arch/arm/kernel/ptrace.c中屬於ARM平台的arch_ptrace實作,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="808">SYSCALL_DEFINE4(<strong>ptrace</strong>, long, request, long, <strong>pid</strong>, unsigned long, addr,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long, data)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct task_struct *child;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
long ret;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (request == PTRACE_TRACEME) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_traceme();</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (!ret)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arch_ptrace_attach(current);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
goto out;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>child</strong> = ptrace_get_task_struct(<strong>pid</strong>);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (IS_ERR(child)) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = PTR_ERR(child);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
goto out;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (request == PTRACE_ATTACH) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_attach(child);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/*</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* Some architectures need to do book-keeping after</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* a ptrace attach.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*/</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (!ret)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arch_ptrace_attach(child);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
goto out_put_task_struct;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_check_attach(child, request == PTRACE_KILL);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (ret < 0)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
goto out_put_task_struct;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = <strong>arch_ptrace</strong>(<strong>child</strong>, request, addr, data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
out_put_task_struct:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
put_task_struct(child);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
out:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ret;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
之後進入到arch_ptrace中執行跟ARM處理器有關的ptrace command,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="808">long <strong>arch_ptrace</strong>(struct task_struct *<strong>child</strong>, long request,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long addr, unsigned long data)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int ret;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long __user *datap = (unsigned long __user *) data;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
switch (request) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_PEEKUSR:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_read_user(<strong>child</strong>, addr, datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_POKEUSR:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_write_user(<strong>child</strong>, addr, data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = copy_regset_to_user(<strong>child</strong>,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
&user_arm_view, REGSET_GPR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0, sizeof(struct pt_regs),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = copy_regset_from_user(<strong>child</strong>,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
&user_arm_view, REGSET_GPR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0, sizeof(struct pt_regs),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETFPREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = copy_regset_to_user(<strong>child</strong>,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
&user_arm_view, REGSET_FPR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0, sizeof(union fp_state),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETFPREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = copy_regset_from_user(<strong>child</strong>,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
&user_arm_view, REGSET_FPR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0, sizeof(union fp_state),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef CONFIG_IWMMXT</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETWMMXREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_getwmmxregs(<strong>child</strong>, datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETWMMXREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_setwmmxregs(<strong>child</strong>, datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GET_THREAD_AREA:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = put_user(task_thread_info(<strong>child</strong>)->tp_value,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SET_SYSCALL:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
task_thread_info(<strong>child</strong>)->syscall = data;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef CONFIG_CRUNCH</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETCRUNCHREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_getcrunchregs(<strong>child</strong>, datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETCRUNCHREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_setcrunchregs(<strong>child</strong>, datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef CONFIG_VFP</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETVFPREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = copy_regset_to_user(<strong>child</strong>,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
&user_arm_view, REGSET_VFP,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0, ARM_VFPREGS_SIZE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETVFPREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = copy_regset_from_user(<strong>child</strong>,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
&user_arm_view, REGSET_VFP,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0, ARM_VFPREGS_SIZE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
datap);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef <strong>CONFIG_HAVE_HW_BREAKPOINT</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">//</span></strong><strong><span style="text-decoration-line: underline;">這就是用</span></strong><strong><span style="text-decoration-line: underline;">GDB</span></strong><strong><span style="text-decoration-line: underline;">使用</span></strong><strong><span style="text-decoration-line: underline;">ptrace</span></strong><strong><span style="text-decoration-line: underline;">支援</span></strong><strong><span style="text-decoration-line: underline;">Hardware Breakpoint/WatchPoint </span></strong><strong><span style="text-decoration-line: underline;">的編譯時</span></strong><strong><span style="text-decoration-line: underline;">define</span></strong><strong><span style="text-decoration-line: underline;">選項</span></strong><strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETHBPREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (ptrace_get_breakpoints(<strong>child</strong>) < 0)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return -ESRCH;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_gethbpregs(<strong>child</strong>, addr,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(unsigned long __user *)data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace_put_breakpoints(<strong>child</strong>);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETHBPREGS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (ptrace_get_breakpoints(<strong>child</strong>) < 0)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return -ESRCH;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_sethbpregs(<strong>child</strong>, addr,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(unsigned long __user *)data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace_put_breakpoints(<strong>child</strong>);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
default:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret =<strong> ptrace_request</strong>(<strong>child</strong>, request, addr, data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ret;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若不屬於跟ARM平台有關的ARM ptrace command,就會走到default選項,然透走回屬於Linux Kernel一般性ptrace命令的實作ptrace_request (kernel/ptrace.c)</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="808">int <strong>ptrace_request</strong>(struct task_struct *<strong>child</strong>, long request,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long addr, unsigned long data)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int ret = -EIO;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
siginfo_t siginfo;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
void __user *datavp = (void __user *) data;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long __user *datalp = datavp;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
switch (request) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_PEEKTEXT:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_PEEKDATA:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return generic_ptrace_peekdata(<strong>child</strong>, addr, data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_POKETEXT:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_POKEDATA:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return generic_ptrace_pokedata(<strong>child</strong>, addr, data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef PTRACE_OLDSETOPTIONS</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_OLDSETOPTIONS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETOPTIONS:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_setoptions(<strong>child</strong>, data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETEVENTMSG:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = put_user(<strong>child</strong>->ptrace_message, datalp);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETSIGINFO:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_getsiginfo(<strong>child</strong>, &siginfo);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (!ret)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = copy_siginfo_to_user(datavp, &siginfo);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETSIGINFO:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (copy_from_user(&siginfo, datavp, sizeof siginfo))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = -EFAULT;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_setsiginfo(<strong>child</strong>, &siginfo);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_DETACH: /* detach a process that was attached. */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_detach(<strong>child</strong>, data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef CONFIG_BINFMT_ELF_FDPIC</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETFDPIC: {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct mm_struct *mm = get_task_mm(<strong>child</strong>);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long tmp = 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = -ESRCH;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (!mm)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
switch (addr) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETFDPIC_EXEC:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
tmp = mm->context.exec_fdpic_loadmap;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETFDPIC_INTERP:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
tmp = mm->context.interp_fdpic_loadmap;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
default:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mmput(mm);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = put_user(tmp, datalp);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef PTRACE_SINGLESTEP</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SINGLESTEP:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef PTRACE_SINGLEBLOCK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SINGLEBLOCK:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef PTRACE_SYSEMU</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SYSEMU:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SYSEMU_SINGLESTEP:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SYSCALL:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_CONT:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ptrace_resume(<strong>child</strong>, request, data);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_KILL:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (<strong>child</strong>->exit_state) /* already dead */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ptrace_resume(<strong>child</strong>, request, SIGKILL);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef CONFIG_HAVE_ARCH_TRACEHOOK</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_GETREGSET:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
case PTRACE_SETREGSET:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct iovec kiov;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct iovec __user *uiov = datavp;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (!access_ok(VERIFY_WRITE, uiov, sizeof(*uiov)))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return -EFAULT;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (__get_user(kiov.iov_base, &uiov->iov_base) ||</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__get_user(kiov.iov_len, &uiov->iov_len))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return -EFAULT;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ptrace_regset(<strong>child</strong>, request, addr, &kiov);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (!ret)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = __put_user(kiov.iov_len, &uiov->iov_len);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
default:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ret;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關ptrace System Call運作流程,可以參考如下圖所示,統一的入口為ptrace System Call(實作在kernel/ptrace.c),之後呼叫跟平台有關的arch_ptrace實作(檔案在 arch/arm/kernel/ptrace.c),最後才是由跟平台有關的arch_ptrace在發現有無法處理的ptrace command時,就會透過ptrace_request函式(實作在kernel/ptrace.c)執行跟處理器無關的ptrace command.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0UTjJ32R8D-oY9YyhJ7tJ0cVk_OpafezKa0y3WY7gQIIAViKDuiXLIFhKLLz-xeEcfg_gChnn7QY3VIKADrwXXcAsSKSjQ9DsEPu5Zv_FkaAr9iitTwT4Xpf8jUltqYsBgS4mJGfwfSk/s1600/image006%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="510" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0UTjJ32R8D-oY9YyhJ7tJ0cVk_OpafezKa0y3WY7gQIIAViKDuiXLIFhKLLz-xeEcfg_gChnn7QY3VIKADrwXXcAsSKSjQ9DsEPu5Zv_FkaAr9iitTwT4Xpf8jUltqYsBgS4mJGfwfSk/s1600/image006%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下,我們舉由GDB對被除錯的Process虛擬位址空間的WatchPoint進行設定的流程為例,說明如下,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, main (gdb/gdb.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,captured_main (gdb/main.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,captured_command_loop (gdb/main.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,current_interp_command_loop (gdb/interps.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,cli_command_loop (gdb/event-top.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,start_event_loop (gdb/event-loop.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>主要的輸入</strong><strong>Event Loop</strong><strong>迴圈</strong><strong>,</strong><strong>會不斷在此等待使用者輸入命令</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,gdb_do_one_event(gdb/event-loop.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>會處理每一個輸入的按鍵</strong><strong>Event.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,process_event(gdb/event-loop.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>會判斷使用者輸入的</strong><strong>Command,</strong><strong>把處理對應</strong><strong>Command</strong><strong>的函式指標</strong><strong>“proc = event_ptr->proc;”</strong><strong>設定給區域變數</strong><strong>”event_handler_func *proc;”,</strong><strong>並進行後續呼叫</strong><strong> “(*proc) (data);”</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9,print_mention_watchpoint (gdb/breakpoint.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>執行</strong><strong> ” watch </strong><strong>變數</strong><strong>” </strong><strong>時</strong><strong>,</strong><strong>會把每次使用者透過</strong><strong> “watch </strong><strong>變數</strong><strong>” </strong><strong>所設定的 </strong><strong>watchpoint </strong><strong>列出來</strong><strong>.</strong><strong>例如</strong><strong>: “Hardware watchpoint 2: MyVariable”.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10,之後執行指令 run,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
11,insert_bp_location (gdb/breakpoint.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>透過這函式對指定記憶體進行</strong><strong>BreakPoint/WatchPoint</strong><strong>設定</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
12.insert_watchpoint(gdb/breakpoint.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>由於筆者是以</strong><strong>WatchPoint</strong><strong>為例</strong><strong>,</strong><strong>所以在函式</strong><strong>insert_bp_location</strong><strong>中會判斷這是一個</strong><strong>Hardware WatchPoint</strong><strong>的</strong><strong>Type (=bp_loc_hardware_watchpoint),</strong><strong>之後透過</strong><strong> ”bl->owner->ops->insert_location”</strong><strong>進入到函式</strong><strong>insert_watchpoint</strong><strong>中</strong><strong>. </strong><strong>會根據該變數所在的記憶體位址與該變數</strong><strong>Type</strong><strong>所對應的記憶體</strong><strong>Size(</strong><strong>例如 </strong><strong>int </strong><strong>為</strong><strong>4 bytes) </strong><strong>進行函式</strong><strong>target_insert_watchpoint</strong><strong>的呼叫</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
13,target_insert_watchpoint (gdb/target.h)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>可以參考 </strong><strong>gdb/target.h</strong><strong>中的宣告</strong><strong>, “#define target_insert_watchpoint(addr, len, type, cond) (*current_target.to_insert_watchpoint) (addr, len, type, cond)”,</strong><strong>得知</strong><strong>GDB</strong><strong>會依據平台與作業系統的不同</strong><strong>,</strong><strong>而對</strong><strong>target_insert_watchpoint</strong><strong>有不同的實作</strong><strong>,</strong><strong>進一步參考</strong><strong>current_target</strong><strong>的宣告</strong><strong>”struct target_ops current_target;”,</strong><strong>我們可以在</strong><strong>ARM Linux GDB</strong><strong>初始化過程中在函式</strong><strong>_initialize_arm_linux_nat(gdb/arm-linux-nat.c)</strong><strong>中看到對應的初始化動作 </strong><strong>“t->to_insert_watchpoint = arm_linux_insert_watchpoint;”, </strong><strong>也因此我們知道從</strong><strong>target_insert_watchpoint </strong><strong>的呼叫之後會進入函式</strong><strong>arm_linux_insert_watchpoint .</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
14, arm_linux_insert_watchpoint (gdb/arm-linux-nat.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>依據平台的不同,例如x86的電腦則會呼叫函式i386_insert_watchpoint (gdb/i386-nat.c),而在ARM平台則是呼叫函式arm_linux_insert_watchpoint . 在這函式流程中,首先會透過函式arm_linux_get_hw_watchpoint_count確認平台上Hardware WatchPoint的數目,若為0就直接結束.再來就是透過函式arm_linux_hw_watchpoint_initialize初始化結構”struct arm_linux_hw_breakpoint *p” 以便之後設定WatchPoint初始值給 WVR(Watchpoint Value Register) 與 WCR (Watchpoint Control Register) 對應的兩個暫存器.WCR 所設定的初值包括</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="72">1</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="733">Watchpoint enable[0]=1</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="72">2</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="733">Privileged access control[2:1]=b11 (Kernel/User存取都能觸發)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="72">3</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="733">Load/store access[4:3]=觸發的可讀寫條件. (例如:b01讀取才觸發,b10寫入才觸發,b11讀寫都觸發)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="72">4</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="733">Byte address select[8:5]=由於ARM都是32-bits進行Fecth的動作,但同時包括ARM32bits,Thumb16bits或Thumb2 16/32bits混合模式,可在此設定比對的位址是要<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(a)b1111:32-bits對齊位址的4bytes都吻合,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(b)b0011:32-bits對齊位址的前2bytes吻合,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(c)b1100:32-bits對齊位址的後2bytes吻合</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
15,arm_linux_insert_hw_breakpoint1 (gdb/arm-linux-nat.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>透過</strong><strong>arm_linux_get_hw_watchpoint_count</strong><strong>取得</strong><strong>Hardware WatchPoint</strong><strong>個數與透過</strong><strong>arm_hwbp_control_is_enabled</strong><strong>找出目前可以使用的</strong><strong>Hardware WatchPoint,</strong><strong>並透過兩次</strong><strong>ptrace PTRACE_SETHBPREGS</strong><strong>命令</strong><strong>,</strong><strong>帶入</strong><strong>Thread ID</strong><strong>依序設定 </strong><strong>WVR(Watchpoint Value Register) </strong><strong>與 </strong><strong>WCR (Watchpoint Control Register) </strong><strong>所要使用的兩個</strong><strong>WatchPoint Address/Control</strong><strong>暫存器</strong><strong>.</strong><strong>值得參考的是</strong><strong>,</strong><strong>在這屬於</strong><strong>WatchPoint</strong><strong>的</strong><strong>Request dir</strong><strong>參數會為負值</strong><strong>,</strong><strong>對</strong><strong>Kernel</strong><strong>提供的</strong><strong>ptrace System Call</strong><strong>來說</strong><strong>,</strong><strong>這個值會對應到</strong><strong>Num</strong><strong>參數</strong><strong>,</strong><strong>而若這值為負值就表示為判斷讀寫</strong><strong>(RW)</strong><strong>動作的</strong><strong>WatchPoint,</strong><strong>反之如果為正值</strong><strong>,</strong><strong>就表示為判斷執行動作的</strong><strong>BreakPoint.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
16,<strong><span style="text-decoration-line: underline;">之後便透過</span></strong><strong><span style="text-decoration-line: underline;">ptrace System Call</span></strong><strong><span style="text-decoration-line: underline;">進入到</span></strong><strong><span style="text-decoration-line: underline;">Kernel Mode.</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17,SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long, data) (kernel/ptrace.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>如</strong><strong>ptrace System Call</strong><strong>進入到</strong><strong>Kernel Space</strong><strong>的入口</strong><strong>,</strong><strong>會依據</strong><strong>pid</strong><strong>透過函式</strong><strong>ptrace_get_task_struct</strong><strong>取得</strong><strong>Task Struct,</strong><strong>與進入屬於平台相關的</strong><strong>arch_ptrace</strong><strong>函式中 </strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18,arch_ptrace (arch/arm/kernel/ptrace.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>由於</strong><strong>Request Type</strong><strong>為</strong><strong>PTRACE_SETHBPREGS,</strong><strong>便會呼叫函式</strong><strong>ptrace_sethbpregs,</strong><strong>而帶入的</strong><strong>addr</strong><strong>會等於函式</strong><strong>ptrace_sethbpregs</strong><strong>的</strong><strong>num,data</strong><strong>則為</strong><strong>User Space</strong><strong>的</strong><strong>“unsigned long __user *data” </strong><strong>對應到上層</strong><strong>User Space</strong><strong>記憶體空間</strong><strong>,</strong><strong>就是要設定給</strong><strong>WatchPoint</strong><strong>的</strong><strong>WVR</strong><strong>或</strong><strong>WCR</strong><strong>的</strong><strong>User Space</strong><strong>數值位址 </strong><strong>(&bpt->address for WVR</strong><strong>或 </strong><strong>&bpt->control for WCR)</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
19,ptrace_sethbpregs (arch/arm/kernel/ptrace.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>對</strong><strong>watchPoint</strong><strong>來說</strong><strong>num</strong><strong>為負值</strong><strong>,</strong><strong>所以</strong><strong>implied_type</strong><strong>會為</strong><strong>HW_BREAKPOINT_RW,</strong><strong>也就表示為</strong><strong>WatchPoint</strong><strong>的記憶體數值讀寫操作</strong><strong>.</strong><strong>在這函式中</strong><strong>,</strong><strong>會透過</strong><strong>get_user</strong><strong>把</strong><strong>User Space</strong><strong>的</strong><strong>WatchPoint Address</strong><strong>與 </strong><strong>Control</strong><strong>所在記憶體中的數值拷貝到</strong><strong>Kernel Space</strong><strong>給區域變數</strong><strong>”u32 user_val”. </strong><strong>若目前</strong><strong>Task</strong><strong>對應這個</strong><strong>Hardware WatchPoint</strong><strong>是第一次產生的</strong><strong>,</strong><strong>此時</strong><strong>“tsk->thread.debug.hbp[idx]”</strong><strong>為</strong><strong>0,</strong><strong>會透過函式</strong><strong>ptrace_hbp_create,</strong><strong>產生給這個</strong><strong>Task.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
20,modify_user_hw_breakpoint (kernel/events/hw_breakpoint.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>=></strong><strong>把使用者</strong><strong>WatchPoint</strong><strong>的調整</strong><strong>,</strong><strong>修改到對應的資料結構中</strong><strong>,</strong><strong>以便之後程式重新執行時</strong><strong>,</strong><strong>可以致能發揮作用</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,讓我們針對Linux Kernel Undefined Instruction Exception的延伸應用加以說明,以供相關開發者可以在後續其它產品中參考之用.</div>
<h1 id="15582_linux-kernel-%e5%b0%_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
Linux Kernel 對 Undefined Instruction Exception 應用的延伸</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在GDB軟體BreakPoint以外,筆者覺得比較經典的案例為Linux Kernel模擬User-Space ARMv32的SWP/SWPB指令集處理函式swp_handler (in arch/arm/kernel/swp_emulate.c),透過註冊如下的 undef_hook swp_hook,我們可以知道這個SWP/SWPB模擬指令集在運作時,是必須在Thumb Bit與Jazzel Bit都不為1的ARMv32 Mode的情況下(也就是非Thumb/ThumbEE Mode)才會成立.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/*</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* Only emulate SWP/SWPB executed in ARM state/User mode.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* The kernel must be SWP free and SWP{B} does not exist in Thumb/ThumbEE.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*/</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static struct undef_hook swp_hook = {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.instr_mask = 0x0fb00ff0,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.instr_val = 0x01000090,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.cpsr_mask = MODE_MASK | PSR_T_BIT | PSR_J_BIT,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.cpsr_val = USR_MODE,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.fn = swp_handler</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡要說明這個SWP/SWPB實作的背景,在多工尤其是多核心的環境下,會有多個Task共用同樣的系統資源,但這些共用的資源如何進行同步(例如使用Mutex or Semaphore),以確保正確性,就是在軟體設計上重要的議題. 基於此,若能有處理器層級的指令集支援,確保共用的資源在多核心多工的架構下,同一時間只有一個Task可以存取更動,將會是最有效率的作法.若無這樣的指令可供使用,通常作法會是把中斷Disable,確保沒有其它中斷或Task有機會插入執行.但這樣的作法對系統效能來說,卻並非最好的選擇.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ARM在ARMv5或之前的架構,支援了SWP(Swap)與SWPB(Swap Byte)兩個指令, 讓有同步需求的環境,可以不必要透過關閉中斷來確保資料的同步無誤,當處理器在進行Swap的過程中收到中斷,ARM處理器會確保整個Swap所包含的Load與Store過程是Atomic的,處理器會延遲中斷的處理,等Swap動作結束才會去進行中斷的執行. 對ARM指令集來說,Load與Store是兩種不同行為的指令,且在多核心的架構下,如果有多個不同頻率的處理器,共用同一個外部記憶體,若要進行Swap行為就會對整體系統效能造成較大的影響.因此Swap指令在ARMv6的架構後,便不建議使用,在開發上ARM則建議開發者改以Ldrex (Load Exclusive)與Strex (Store Exclusive)兩個指令取代SWP指令.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關SWP指令的操作可以參考ARM的網頁 “A.1.1. SWP and SWPB”(<a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dht0008a/CJHBGBBJ.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dht0008a/CJHBGBBJ.html</a> ),有一個簡要的範例如下,可示範如何透過 SWP指令實現 Mutex Lock/Unlock (通常Linux上的Lock值為1表示鎖住,而0表示解鎖,以下例來說,會把1寫入r0所在記憶體代表這個Lock已經鎖上),</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="807">EXPORT lock_mutex_swp<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lock_mutex_swp PROC</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LDR r2, =locked</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SWP r1, r2, [r0] ; Swap R2 with location [R0], [R0] value placed in R1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CMP r1, r2 ; Check if memory value was ‘locked’</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BEQ lock_mutex_swp ; If so, retry immediately</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BX lr ; If not, lock successful, return</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ENDP</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
EXPORT unlock_mutex_swp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unlock_mutex_swp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LDR r1, =unlocked</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
STR r1, [r0] ; Write value ‘unlocked’ to location [R0]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BX lr</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ENDP</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在ARMv7的架構下,針對SWP/SWPB也提供了額外的彈性,可藉由設定CP15 (CoProcessor 15) 的 System Control Register的SW bit為1去決定是否支援SWP或SWPB指令. 更進一步的拓展,就是在Linux Kernel下,基於對於已經Phase-Out的SWP/SWPB進行支援,考量到還是有部分User Mode的應用程式有使用到SWP/SWPB指令(例如GLibc 2.8版本以前所編譯的函式庫),在ARMv7多核心架構下,如果希望避免透過設定CP15 System Control Register的SW bit 為1去支援SWP/SWPB指令,讓使用SWP/SWPB指令的應用程式時,對多核心環境造成影響.Linux Kernel支援了額外的編譯選項”SWP_EMULATE”,會在ARMv7多核心Linux Kernel初始化時把CP15 System Control Register的SW bit 設定為0,讓所運作的ARMv7多核心架構在遇到採用SWP/SWPB的User-Space應用程式時,會因為執行到這不支援的指令集而觸發Undefined Instruction Exception,讓Linux Kernel透過函式swp_handler (in arch/arm/kernel/swp_emulate.c),把SWP/SWPB指令改用__user_swpX_asm中的ldrex與strex兩個指令來實現.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡單來說,就是透過Undefined Instruction Exception的觸發,基於軟體實現了一個原本不支援的ARM指令.</div>
<h1 id="15582_gdb-%e6%8c%87%e4%bb%_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
GDB 指令</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
進入GDB後,可以執行如下的環境變數,或是透過 ‘gdb script-file ‘ 外部執行Script 檔案,減少要在GDB中配置環境變數的不便.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>file</strong> <strong>builtin-symbol-execution-file</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set solib-search-path</strong><strong> builtin-symbol-library-file-path</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set solib-absolute-prefix</strong> <strong>builtin-symbol-library-filepath-prefix</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>core </strong><strong>core-dump-file</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先, GDB指令繁多,不論是書籍 (像是”The Art of Debugging with GDB and DDD”),或是網路上的參考網頁,都已經很豐富,在此僅舉筆者認為值得進一步說明的指令,其它的部份,都請自行參閱其它GDB指令的介紹,或在GDB下透過 help指令尋求解答也是很棒的方式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Break Point</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">指令</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">break</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592"><strong>1,</strong><strong>對函式起點 設定</strong><strong>break point</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>(gdb) b main</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 1 at 0x400557: file test.c, line 23.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,</strong><strong>對目前</strong><strong>Source Code</strong><strong>第</strong><strong>27</strong><strong>行</strong><strong>, </strong><strong>設定</strong><strong>break point</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>(gdb) b 27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 2 at 0x400567: file test.c, line 27.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3,</strong><strong>對記憶體位址</strong><strong>0x400567 , </strong><strong>設定</strong><strong>break point</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>(gdb) b *0x400567</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Note: breakpoint 2 also set at pc 0x400567.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 3 at 0x400567: file test.c, line 27.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>4,</strong><strong>對特定行數的 </strong><strong>break point,</strong><strong>加上條件判斷</strong><strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,想在函式 thread_func中的區域變數i為30時,觸發斷點,就可以在 break 指令後,加上 if 條件式的判斷</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) list 10</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 void thread_func()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6 {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7 int i=0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8 while(1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9 {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10 i++;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
11 printf(“Thread:%ld\n”,i);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
12 if(i>99)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
13 gCount=-1;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
14 sleep(1);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) b 12 if i==30</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 1 at 0x4005de: file test2.c, line 12.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或像是</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) b 12 if (i==30 && X=5)</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) b 12 if (X%50==0)</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;"></span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;"></span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>5,</strong><strong>對指定檔案與指定行數</strong><strong>, </strong><strong>設定</strong><strong>break point</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) break TestA.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 2 at 0x400557: file TestA.c, line 23.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>6,</strong><strong>對指定檔案的函式</strong><strong>, </strong><strong>設定</strong><strong>break point</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) break TestA.c:main</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 1 at 0x400557: file TestA.c, line 23.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">command</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">command 指令可以讓每個break point暫停的位置去執行預設想要執行的Script,包括可以透過printf列印出變數,或透過 if/else 條件判斷式,while/for 條件式的還圈,可以讓command執行GDB Script讓除錯的流程與機制更加便利<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) b main</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 1 at 0x400557: file TestA.c, line 23.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) command 1</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Type commands for when breakpoint 1 is hit, one per line.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
End with a line saying just “end”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>printf “I am break point 1\n”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>end</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) b 26</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 2 at 0x400582: file TestA.c, line 26.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) command 2</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Type commands for when breakpoint 2 is hit, one per line.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
End with a line saying just “end”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>printf “I am break point 2\n”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>end</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
已經設定Command內容給BreakPoint 1與 2,因此接下來可以透過Run來觸發BreakPoint以便可以執行Command內容.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) r</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Starting program: /home/loda/test/TestA</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 1, main () at TestA.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
warning: Source file is more recent than executable.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
23 int Y=99;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
I am break point 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.25.el6_1.3.x86_</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
64</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) c</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Continuing.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FuncB:198556181</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FuncA:198556181</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
main:14061</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 2, main () at TestA.c:26</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
26 return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
I am break point 2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果希望command不要顯示額外的訊息,可以在command一開始加上silent.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">define</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">透過define把要在command指令中定義的命令包裝起來,作為自己往後操作Command指令時的前置宣告巨集使用<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) define show_arg_and_go_to_continue</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Type commands for definition of “show_arg_and_go_to_continue”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
End with a line saying just “end”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>printf $arg0,$arg1,$arg2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>continue</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>end</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) b main</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Breakpoint 1 at 0x400557: file TestA.c, line 23.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
設定Command 1並使用剛才定義好的 show_arg_and_go_to_continue指令串</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) command 1</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Type commands for when breakpoint 1 is hit, one per line.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
End with a line saying just “end”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>silent</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>show_arg_and_go_to_continue “It is my test:%ld %s\n” Y “Test la”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
>end</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行Run指令以便啟動程式執行</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) r</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Starting program: /home/loda/test/TestA</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
It is my test:0 Test la</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FuncB:198556181</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FuncA:198556181</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
main:14061</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Program exited normally.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">info break</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">用以顯示目前所有配置的Break Point位置與行號<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>(gdb) info b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Type Disp Enb Address What</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 breakpoint keep y 0x0000000000400557 in main at test.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
breakpoint already hit 1 time</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">clear</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">刪除位於指定行數的Break Point配置<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>(gdb) info b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Type Disp Enb Address What</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 breakpoint keep y 0x0000000000400557 in main at test.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
breakpoint already hit 1 time</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) clear 27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Deleted breakpoints 2 3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">delete</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">刪除指定的Break Point編號<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>(gdb) info b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Type Disp Enb Address What</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 breakpoint keep y 0x0000000000400557 in main at test.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
breakpoint already hit 1 time</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) delete 1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) info b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Type Disp Enb Address What</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">disable</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">關閉指定的Break Point編號<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>(gdb) info b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Type Disp Enb Address What</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6 breakpoint keep y 0x0000000000400557 in main at test.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) disable 5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) info b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Type Disp Enb Address What</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 breakpoint keep n 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6 breakpoint keep y 0x0000000000400557 in main at test.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">enable</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">重新致能指定的Break Point編號<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=>(gdb) info b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Type Disp Enb Address What</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 breakpoint keep n 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6 breakpoint keep y 0x0000000000400557 in main at test.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) enable 5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) info b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Num Type Disp Enb Address What</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 breakpoint keep y 0x0000000000400567 in main at test.c:27</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6 breakpoint keep y 0x0000000000400557 in main at test.c:23</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Back Trace</strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="216">指令</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="595">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="216">bt</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="595">Backtrace可以用來依據目前的PC/LR與r13 Sp暫存器,顯示當下的Call Stack Back Trace,用以讓開發者可以了解目前的函式呼叫流程,以便可以分析最後問題的現場與發生的原因.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示為Backtrcae指令的演示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) bt</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#0 FuncB (X=14061) at TestA.c:6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x0000000000400530 in FuncA (X=99) at TestA.c:17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#2 0x0000000000400568 in main () at TestA.c:24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也可以透過Backtrace把整個Call Stack Back Trace把有關的函式變數與區域變數值給顯示出來,如下所示為Backtrace full指令的演示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) bt full</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#0 FuncB (X=14061) at TestA.c:6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y = 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x0000000000400530 in FuncA (X=99) at TestA.c:17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y = 14061</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Z = 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#2 0x0000000000400568 in main () at TestA.c:24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Y = 99</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="216">frame</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="595">假設現在Back Tree有如下3層<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) bt</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#0 FuncB (X=14061) at TestA.c:6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x0000000000400530 in FuncA (X=99) at TestA.c:17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#2 0x0000000000400568 in main () at TestA.c:24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
frame 0 既是現在所在的位置,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以透過 print 查看當下的 X與Y變數的值</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) list FuncB</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1 #include <stdio.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3 int FuncB(int X)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4 {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5 int Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6 Y=X+40;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7 Y*=X+20;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8 printf(“FuncB:%ld\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9 return Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10 }</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) p X</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$1 = 14061</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) p Y</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$2 = 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
frame 1 是在FuncA呼叫進入FuncB時的狀態,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) frame 1</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x0000000000400530 in FuncA (X=99) at TestA.c:17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17 Z=FuncB(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) list 16</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
11 int FuncA(int X)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
12 {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
13 int Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
14 int Z;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
15 Y=X+10;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
16 Y*=X+30;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17 Z=FuncB(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18 printf(“FuncA:%ld\n”,Z);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
19 return Y;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
20 }</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) p X</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$4 = 99</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) p Y</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$5 = 14061</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) p Z</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$6 = 0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
frame2 是在main呼叫進入FuncA時的狀態,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) frame 2</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#2 0x0000000000400568 in main () at TestA.c:24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
24 Y=FuncA(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) list 26</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
21 int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
22 {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
23 int Y=99;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
24 Y=FuncA(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
25 printf(“main:%ld\n”,Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
26 return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
27 }</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) p Y</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$7 = 99</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="216">down</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="595">可以讓開發者在位於Call Stack後端的Frame,透過 down指令依序往Frame #0方向移動.基本的演示如下所示<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) bt</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#0 FuncB (X=14061) at TestA.c:6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x0000000000400530 in FuncA (X=99) at TestA.c:17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#2 0x0000000000400568 in main () at TestA.c:24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) frame 2</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#2 0x0000000000400568 in main () at TestA.c:24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
24 Y=FuncA(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) down</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x0000000000400530 in FuncA (X=99) at TestA.c:17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17 Z=FuncB(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) down</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#0 FuncB (X=14061) at TestA.c:6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6 Y=X+40;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="216">up</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="595">可以讓開發者在位於Call Stack前端的Frame,透過 up指令依序往Frame #2方向移動.基本的演示如下所示<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) bt</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#0 FuncB (X=14061) at TestA.c:6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x0000000000400530 in FuncA (X=99) at TestA.c:17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#2 0x0000000000400568 in main () at TestA.c:24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) up</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x0000000000400530 in FuncA (X=99) at TestA.c:17</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17 Z=FuncB(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) up</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#2 0x0000000000400568 in main () at TestA.c:24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
24 Y=FuncA(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>檢查變數</strong><strong></strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">指令</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">watch</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">watch x<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以用來在變數x值被改變時,觸發Break Point,進行分析</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
watch x > ,< ,==</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以針對watch 動作加上條件判斷,例如 watch x>100 ,就表示當變數x值被改為 > 100時,就觸發Break Point,進行分析</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">print</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">Print指令可以用來顯示變數當下的數值內容,如下所示<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) n</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
24 Y=FuncA(Y);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p Y</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$2 = 99</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也可以設定要顯示的變數Type,例如筆者演示為16進位方式顯示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p /x Y</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$3 = 0x63</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也可以用來顯示struct,例如</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct timeval Now;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long P;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
gettimeofday(&Now, NULL);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
P=(unsigned long)&Now;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…………………..</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以透過如下的 Print指令,搭配Type Casting,把struct內容顯示出來</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p Now</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$1 = {tv_sec = 1331821430, tv_usec = 857355}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p (struct timeval *)P</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$4 = (struct timeval *) 0x7fffffffe570</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p ((struct timeval *)P)->tv_usec</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$5 = 857355</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p ((struct timeval *)P)->tv_sec</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$6 = 1331821430</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p /x ((struct timeval *)P)->tv_usec</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$8 = 0xd150b</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p /x ((struct timeval *)P)->tv_sec</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$9 = 0x4f61fb76</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也可以做邏輯上的運算</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) p (((struct timeval *)P)->tv_usec + ((struct timeval *)P)->tv_sec)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$3 = 1332083044</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">ptype</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">可以透過ptype顯示變數的原始宣告型態<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) ptype Y</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
type = int</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
另一個演示的例子</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) ptype P</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
type = long unsigned int</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或是也可以顯示結構的內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) ptype Now</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
type = struct timeval {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__time_t tv_sec;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__suseconds_t tv_usec;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>流程操作</strong><strong></strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">指令</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">run</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">執行程式,若該程式有參數 例如,test 1 2 3,在這就可以執行run 1 2 3 讓應用程式main的 argv與argc操作可以執行.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">finish</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">等於step out,也就是把函式執行完畢後return暫停</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">next</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">等於step over,也就是在同一層函式中執行,呼叫到副函式時,不會進入執行,會等該副函式執行完畢後,繼續往下一行執行</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">step</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">等於step in,也就是在同一層函式中執行,呼叫到副函式時,會一路跟進下一層執行,若發現跟進下一層後,路徑太長而希望回到上一層的話,就可以透過finish把目前函式執行完畢後,回到上一層進入這函式入口的下一個指令.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">until</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">執行程式碼,直到執行到for/while下一個循環程式碼的下一行Source Code.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">continue</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">這指令式在程式執行run後,因為break point觸發,或使用者自己透過ctrl+c讓正在執行中的程式中斷執行後,等使用者把相關要加上的break point加上,或是要觀察的變數與Source Code確認完畢後,就可以透過continue指令,讓程式在剛才中斷的位置繼續執行下去.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>查閱記憶體內容</strong><strong></strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">指令</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">dump</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">可以透過如下指令把記憶體內容Dump到外部檔案中<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dump memory /path start-address end-address</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如可以把已知是一個Mpeg Video檔案格式的記憶體內容Dump出來,作為除錯的目的之用.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dump memory ~/video.mpg 0x41000000 0x42000000</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="219">X</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="592">列印十六進位的資料<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x/8xw $sp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
把PC記憶體內容反組譯為指令</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x/8iw $pc</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或是把 main函式記憶體內容反組譯為指令</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) x /8iw main</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x842c <main>: push {r11, lr}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8430 <main+4>: add r11, sp, #4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8434 <main+8>: ldr r0, [pc, #12] ; 0x8448 <main+28></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8438 <main+12>: bl 0x8374 <sleep></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x843c <main+16>: mov r3, #0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8440 <main+20>: mov r0, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8444 <main+24>: pop {r11, pc}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8448 <main+28>: addseq r9, r8, pc, ror r6</div>
</td></tr>
</tbody></table>
<h1 id="15582_gdb-script_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
GDB Script</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基本的環境變數組成</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>file</strong> <strong>builtin-symbol-execution-file</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set solib-search-path</strong><strong> builtin-symbol-library-file-path</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set solib-absolute-prefix</strong> <strong>builtin-symbol-library-filepath-prefix</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>core </strong><strong>core-dump-file</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GDB本身除了大家熟知的指令外,還包括對於GDB Script的支援,像是一般常見的變數宣告(set),if/else,while這些條件判斷與迴圈的支援,都可讓使用GDB環境的開發者,基於GDB Script建構一個強大的分析環境.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下筆者列出自己常用到的Script寫法</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>寫出檔案</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Set logging file output.txt</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>開啟</strong><strong>Logging</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Set logging on</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>設定變數</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Set $xxx=0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Set $i=0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>列印字串 </strong><strong>print</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Print “xxxx”,$xxx,”yyyy\n”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>讀取全域變數的資料結構</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Set $abc = gTable->ItemIndex</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>設定 </strong><strong>while</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
While($i<1024)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>設定變數結構的讀取</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Set $String=($abc)[$i]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>if/else</strong><strong>條件判斷</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
End</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>設定</strong><strong>print out</strong><strong>格式</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
x /16xw $addr</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>關閉</strong><strong>Logging</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Set logging off</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
網路上有很多關於GDB Script語法介紹的網站,在此就不累述,有興趣的開發者請自行參閱即可.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<h1 id="15582_%e5%8f%83%e8%80%83%e_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
參考幾個 GDB 處理實例</h1>
<div>
<h1 id="15582_%e6%a1%88%e4%be%8b-a_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
案例 #A: 如果應用程式 Stack 被覆蓋</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
通常遇到這樣的問題,會導致GDB BackTrace無法解析出正確的結果,例如下面的例子,我們可以透過bt full去查看目前掛掉應用程式Core Dump的Back Trace內容,但因為有Stack記憶體區塊損壞的問題,所以導致Back Trace的內容不正確</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH0AlEGoSstVnYL5ZEdW_-T5L9nRq-qpYjUEBh6C34gMPq6t4-u6v-ZkN6SpJSVhaslEPQokunxu2LWfWrNeKhNexAVLaWau-spYJGvXgusAz0OuYX2c-VNq7R9MfEEALNIIUINGPyLqI/s1600/image008%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="92" data-original-width="756" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH0AlEGoSstVnYL5ZEdW_-T5L9nRq-qpYjUEBh6C34gMPq6t4-u6v-ZkN6SpJSVhaslEPQokunxu2LWfWrNeKhNexAVLaWau-spYJGvXgusAz0OuYX2c-VNq7R9MfEEALNIIUINGPyLqI/s1600/image008%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">如果根據現場的行為判定,Stack可能是部分損壞,我們可以先透過info registers確認目前r12,r13與14的內容</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcbRckTxoaVKKc_-9RPd3qSpvLh5yxzVgsKKDkT0dM2ucXmi9PPdBA1240JcmTPZNzQcrJsm2si1ESFxoRp_qYe0IpoL1lL-LwXPatfBfqAbp4Ta8KJWl22cobe1qRcYzKt648SEtzsFU/s1600/image010%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="289" data-original-width="440" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcbRckTxoaVKKc_-9RPd3qSpvLh5yxzVgsKKDkT0dM2ucXmi9PPdBA1240JcmTPZNzQcrJsm2si1ESFxoRp_qYe0IpoL1lL-LwXPatfBfqAbp4Ta8KJWl22cobe1qRcYzKt648SEtzsFU/s1600/image010%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">然後透過UltraEdit去搜尋r12,r13與14三個暫存器連續的12 bytes值 (0x68231940A84874559F361440),如下圖所示</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCAYkNVtmSzl4JE4DcqX10kSrp32uiH8k9JeXIFCREueksQ3JMH8IB6AmC_4PpyAsEgXQCblZpifNnyGXqvCpAzctkisRlOYf1ujamF-0xzGo2Oh0DpqHRI2DcOZVTAZc7RUb_Mnmqemo/s1600/image012%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="347" data-original-width="630" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCAYkNVtmSzl4JE4DcqX10kSrp32uiH8k9JeXIFCREueksQ3JMH8IB6AmC_4PpyAsEgXQCblZpifNnyGXqvCpAzctkisRlOYf1ujamF-0xzGo2Oh0DpqHRI2DcOZVTAZc7RUb_Mnmqemo/s1600/image012%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">找到後,我們透過指令 x/8xw $sp 確認可能有效的Stack起點,如下所示,筆者根據問題的判斷,選擇把Stack起點從0x557448a8設為0x557448b8</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYyYTm8tn7xtEikhCtr_WqgTQu-NrjENj_7f_QdRCe7hJ_gtHn5aVVX4O29GfbloMglrRLXGWivoNZ0iPCYtkOXqnINGXrZfMZ4NmDWWIACBek4mv690kP4jQH8DgCdsLPwBhAvo6GjUM/s1600/image014%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="91" data-original-width="594" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYyYTm8tn7xtEikhCtr_WqgTQu-NrjENj_7f_QdRCe7hJ_gtHn5aVVX4O29GfbloMglrRLXGWivoNZ0iPCYtkOXqnINGXrZfMZ4NmDWWIACBek4mv690kP4jQH8DgCdsLPwBhAvo6GjUM/s1600/image014%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">如下所示透過UltraEdit修改,並進行儲存Core Dump的動作</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHMtqif3noqXbiv8CMBmJMJD8gqG_0aUAYOCDffR6HrSySt514_tNgTT23NKKpyT0LYbXtY1IGmsWX30ovOoXu3gVjYQpO3DlFf7TrpEg5HxBiHY22HNzR6phls0tpq4ak5LJV4OaJUh0/s1600/image016%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="95" data-original-width="525" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHMtqif3noqXbiv8CMBmJMJD8gqG_0aUAYOCDffR6HrSySt514_tNgTT23NKKpyT0LYbXtY1IGmsWX30ovOoXu3gVjYQpO3DlFf7TrpEg5HxBiHY22HNzR6phls0tpq4ak5LJV4OaJUh0/s1600/image016%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">重新載入有被修改內容的Core Dump,如下所示SP(r13)暫存器被設定為0x557448b8,</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoevS8k8-LqhH_D0hFMddzsjuOBnNEztTGK0qkhgbk7L0AL1_Rk4dm8fdIM69ltQX6eemSSpdA_eU-IMke0u1kGCDc31QMf9oAGqvHNQ9SE6ghVJIpSlcXomp_R-ueZUIrYNtYO6ezO3s/s1600/image018%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="297" data-original-width="460" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoevS8k8-LqhH_D0hFMddzsjuOBnNEztTGK0qkhgbk7L0AL1_Rk4dm8fdIM69ltQX6eemSSpdA_eU-IMke0u1kGCDc31QMf9oAGqvHNQ9SE6ghVJIpSlcXomp_R-ueZUIrYNtYO6ezO3s/s1600/image018%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">基於新的Stack起點,重新透過 bt 指令,可以看到正確的 Back Trace被解析出來,藉此我們就可以去推敲是因為怎樣的原因導致最後的Stack內容被覆蓋,以及在怎樣的情況下,會讓ARM Program Counter執行到最後問題發生的所在位置</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2IcIHTIIIzBDcJ5E16VaoCX43vMbA8VA3k-uTERjYxa831cgfoYUdgvlXQhnchT1IIcEYoatS0AcqcbAPcMri6AaPOW1osqror2cTgUyjRvjSqgt75UsumsiXIEKwu0w8s_CbwS3ZeDY/s1600/image020%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="282" data-original-width="828" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2IcIHTIIIzBDcJ5E16VaoCX43vMbA8VA3k-uTERjYxa831cgfoYUdgvlXQhnchT1IIcEYoatS0AcqcbAPcMri6AaPOW1osqror2cTgUyjRvjSqgt75UsumsiXIEKwu0w8s_CbwS3ZeDY/s1600/image020%255B1%255D.png" /></a></div>
<h1 id="15582_%e6%a1%88%e4%be%8b-b_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
案例 #B: 程式執行過程 , 被資料溢位覆蓋</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
通常在軟體整合過程中,包括來自Linux Kernel中撰寫不適當的Driver,或是硬體DMA的值錯誤,或在操作所配置的記憶體區塊時,因為沒有考慮到邊界問題,導致有大面積的資料溢位覆蓋時,通常可以透過GDB把這整塊覆蓋過去的記憶體內容 dump出來,以便透過格式的分析找出可能是被哪類大量搬移的資料所覆蓋.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dump memory /path start-address end-address</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dump memory /loda/IAMImage.raw 0x41000000 0x42000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
通常如果是儲存裝置的DMA搬移,在這塊記憶體中就會有相關檔案的內容甚至是明確的檔頭,又或者是因為被多媒體的資料內容所覆蓋,在這塊記憶體範圍內就會有16-bits左右聲道的Audio資料,或YUV16資料,或32bits ARGB資料.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
找出疑似覆蓋的資料內容格式後,就可以把問題的追查限縮在有限的範圍內.</div>
<h1 id="15582_%e6%a1%88%e4%be%8b-c_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
案例 #C: 多執行緒下 , 全域變數值被不預期的修改</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
通常在多工環境下,如果有一些資料結構或是變數會不預期的被修改,而又希望可以找出是誰去修改的,就可以透過GDB的watch指令,使用ARM上的Hardware WatchPoint來監視資料是否有被透過ARM處理器的操作而被修改到或滿足特定的條件下,進行除錯斷點的觸發.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但需要注意的是,Hardware WatchPoint只限於透過ARM處理器的存取監控,如果這個變數是被硬體DMA或其它共用外部DRAM的處理器所修改的,就無法透過watch指令進行監控.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下舉一個簡單的例子來加以說明,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="810">int gCount=0;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
void thread_func()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int i=0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
while(1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
i++;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Thread:%ld\n”,i);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(i>99)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
gCount= -1;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
sleep(1);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int i;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pthread_t tid;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pthread_create(&tid,0,(void *)thread_func,0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
sleep(9999999);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行GDB後,透過Watch指令去查看全域變數何時被修改為負值</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) watch gCount<0 </span></strong><strong>=></strong><strong>設定當</strong><strong>gCount </strong><strong>為負值時觸發</strong><strong>watchpoint</strong><strong>中斷點</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Hardware watchpoint 1: gCount<0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) run</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Starting program: /home/loda/test/test2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[Thread debugging using libthread_db enabled]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[New Thread 0x7ffff7831700 (LWP 7860)]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:3</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:5</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……………</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:97</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:98</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:99</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:100</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[Switching to Thread 0x7ffff7831700 (LWP 7860)]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Hardware watchpoint 1: gCount<0 =></strong><strong>在這因</strong><strong>gCount<0 </strong><strong>而觸發硬體的</strong><strong>watchpoint</strong><strong>中斷點</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Old value = 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
New value = 1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
thread_func () at test2.c:14</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
14 sleep(1);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) p gCount</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$1 = -1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) list 14</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9 {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10 i++;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
11 printf(“Thread:%ld\n”,i);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
12 if(i>99)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
13 gCount=-1;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
14 sleep(1); <strong>=></strong><strong>最後是在這行之後</strong><strong>,</strong><strong>符合 </strong><strong>gCount<0.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
15 }</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
16 }</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17 int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18 {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如上述例子,就可在某一條執行緒把全域變數改為負值時,透過watch指令觸發中斷點,暫停程式執行,讓開發者可以去檢視自己程式設計上的缺陷為何.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若是有一個變數,會被不預期寫入任意值,則透過watch 指令,但不加上判斷式,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) watch gCount</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Hardware watchpoint 1: gCount</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">(gdb) run</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Starting program: /home/loda/test/test2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[Thread debugging using libthread_db enabled]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[New Thread 0x7ffff7fe4700 (LWP 7799)]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:3</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…….</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:98</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:99</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Thread:100</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[Switching to Thread 0x7ffff7fe4700 (LWP 7799)]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Hardware watchpoint 1: gCount <strong>=></strong><strong>同前例</strong><strong>,</strong><strong>由於</strong><strong>gCount</strong><strong>值被改變了</strong><strong>,</strong><strong>而觸發</strong><strong>Break Point.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Old value = 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
New value = -1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
thread_func () at test2.c:14</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
14 sleep(1);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb)</div>
<h1 id="15582_%e6%a1%88%e4%be%8b-d_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
案例 #D: 如果 CoreDump 中的 Stack 污染 , 導致回推 Back Trace 被截斷 , 但又想試著把剩下有限的資訊 Debug 出來</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,是筆者在遇到bt指令無法Decode出有意義資訊,或不想手動再透過UltraEdit修改Core Dump中的SP暫存器時,會採用的Stack Decode Script (相信一定有更好的寫法,以下只供參考.).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>file</strong> <strong>builtin-symbol-execution-file</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set solib-search-path</strong><strong> builtin-symbol-library-file-path</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set solib-absolute-prefix</strong> <strong>builtin-symbol-library-filepath-prefix</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>core </strong><strong>core-dump-file</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set print symbol-filename on =></strong><strong>設定</strong><strong>Print Symbol</strong><strong>時</strong><strong>,</strong><strong>把檔案位置與行數也印出</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set logging file stack-out.txt =></strong><strong>把結果寫出到檔案中</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set logging on</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set $stack_addr=$sp</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>printf “Start to decode tack\n”</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set $i=0</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>while($i<256) =></strong><strong>設定依據</strong><strong>SP</strong><strong>暫存器</strong><strong>,</strong><strong>往上把</strong><strong>256*4 </strong><strong>也就是</strong><strong>1024 bytes,</strong><strong>依序進行</strong><strong>Print Symbol</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>printf “i:%ld stack_addr:%xh\n”,$i,$stack_addr</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>print /a *(int *) $stack_addr</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set $stack_addr = $stack_addr +4</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set $i = $i + 1</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>end</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>printf “End\n”</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>set logging off</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
總結上述範例,其實最重要的還是對於系統與處理器的了解,再透過熟悉GDB的命令,就可以在這些平台上,讓GDB成為我們最棒的除錯工具.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<h1 id="15582_%e7%b5%90%e8%aa%9e_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0.3em 0px 10px; padding-bottom: 0px; padding-top: 0px;">
結語</h1>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Linux平台上開發,使用GDB無疑是除錯工具的首選,不論是在Run-Time分析或是發生Core Dump的事後分析工作,GDB都會是讓事情事半功倍的最佳工具.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除錯的技巧,其實只是熟悉而已,真正對解決問題有幫助的還是這些基於處理器與作業系統的抽象概念,與內部細節的理解,希望本文可以帶給大家對於GDB除錯器的進一步認識,也期待在我們周圍可以有更多開發者熟悉這套工具,進而對產品與問題的解決上有更進一步深入探索.當然,如果可能的話,基於分享的理念,時間許可也能參與撰寫技術文章的行列,讓這些技術資訊的普及可以更為無遠弗屆.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文如果有未盡完善之處,還請不吝指教.</div>
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com1tag:blogger.com,1999:blog-1668810802505961314.post-28944862379059284342017-06-03T17:26:00.000-07:002017-06-03T17:26:08.971-07:00Linux Kernel 排程機制介紹<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Linux Kernel 排程機制介紹</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Linux Kernel </strong><strong>排程機制介紹</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
hlchou@mail2000.com.tw</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
by loda.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
2011/12/2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
多核心架構儼然是目前智慧型手機方案的新趨勢,隨著省電與效能上的考量,多核心的架構各家方案也都有所差異.為能讓同一個Linux Kernel在不同效能的處理器上能即時運作,其中關鍵的部份便是核心的排程機制,也因此本文將以此為主題進行介紹,希望能對目前投入這領域的開發者有所助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
前一段時間,看到Qualcomm關於Snapdragon S4產品的新聞,這產品最讓人印象深刻的部份在於它支援aSMP(Asynchronous Symmetrical Multi-Processing)的處理器架構,基於ARMv7 Dual/Quad-Core 的Krait多核心處理器架構,可讓個別處理器根據執行時期的負荷,動態調整時脈(根據晶片型號差異,時脈最高可達 2.5Ghz)與電壓的DCVS (Dynamic Clock and Voltage Scaling)技術. 每個aSMP的處理器都能獨立的調整電壓與時脈,並能夠關閉用不到的處理器,節省功耗. 由於可以根據需求個別調整主處理器的時脈,因此在aSMP架構下,當需要有類似Companion處理器的角色時,就可以把其中一個主處理器降頻,同時兼顧到省電與執行低算運需求的目的 (Qualcomm採用的是28nm,省電製程.). 也因此,就無需在主處理器之外,額外提供一個運算能力較低且低功耗的處理器,用來支援待機或是背景音樂播放的需求.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在同一則新聞中也提到NvidiaTegra3支援的Quad-Core與vSMP(Variable Symmetric Multiprocessing)架構.參考Nvidia的技術文件「Variable SMP – A Multi-Core CPU Architecture for Low Power and High Performance」,我們知道 Tegra3不同於前一代Tegra2是由兩個Cortex A9搭配一個低階ARM7的架構,以NVIDIA Kal -El的vSMP方案來說,會提供五個Cortex A9處理器(組合方式為4 個高效能Cortex A9主處理器 搭配 1個效能較低但強調省電的Cortex A9 Companion處理器),其中4個Cortex A9主處理器採用標準製程(時脈可到GHz.),以訴求較高的執行效率,而剩下一個Companion Cortex A9處理器(時脈最高為500MHz),會採用低功耗(Low Power)的製程,可用於運算量較低的待機或背景執行需求.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於vSMP的架構,這五個處理器,可以根據執行的實際狀況,選擇主處理器或是Companion處理器運作,並透過DVFS(Dynamic Voltage and Frequency Scaling) 動態調整主處理器的頻率與電壓降低功耗,進行Power Gating與利用目前Linux Kernel所支援的CPU Up/Down HotPlug機制,讓4個主處理器可以動態的 CPU-Up/Down 掛起或移出Linux Kernel Tasks的排程範圍(ex,Task Migration),以便讓閒置的處理器關閉節省功耗.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Tegra的WhitePaper,vSMP並不允許Companion處理器與主處理器被同時啟用,也因此Tegra3有提供軟硬體配套的CPU Governor 與 CPU Management Logic 去監控處理器的執行負荷,能在系統繁忙時,關閉Companion CPU,把工作轉到4個主處理器上執行,並監控處理器執行負載,動態調整主時脈與哪個主處理器能被卸載. 也就是說,如果是處於待機或是背景音樂播放,系統就只開啟Companion 處理器,但若是需要上網或執行更繁重的工作,就會卸載Companion 處理器,然後根據需求開啟1個,2個或同時把4個主處理器致能. 基於這樣的設計,也能對主處理器的時脈進行調整,但不同於aSMP架構的是,這4個主處理器的時脈會調整為一樣的時脈,要拉高就一起拉高,要降低就一起降低,因此對Linux Kernel的排程來說,並不會有參與排程的處理器運算能力不一致的問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
相對於上述提到的aSMP或vSMP架構,我們比較跟使用一個效率高的主處理器搭配一個省電且運算能力較弱的Companion處理器的差異,例如 ARM9/ARM11 +DSP 或是一個 Cortex A9 + ARM7,由於這兩個主處理器與Compaion處理器基礎架構不同,兩個處理器的Memory Management與L2 Cache並沒有共用,甚至兩者在指令集的層次就完全不同,例如ARM環境中運作的Linux Kernel配置好的記憶體分頁,或是多工環境下的Tasks,就不能直接透過排程分到DSP上運作.而是必須在設計階段,就考慮到這兩個處理器協同運作的配套機制,例如Linux Kernel,人機介面與檔案系統是運作在ARM端,而Audio Codec是放在DSP上執行,此時會由ARM去處理人機介面互動並透過檔案系統把音樂檔案載入,讓DSP端可以播放. 兩個處理器之間,需要設計彼此溝通的介面機制,隨著應用情境的多元化,在設計上的複雜度也會相對增加.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而aSMP與vSMP的優點在於上面的主處理器與Companion處理器採用同樣的核心技術,有一樣的指令集,共用同樣的Memory Management記憶體管理與L2 Cache共用. 以vSMP來說, Companion處理器跟主處理器有各自的L1 Cache,但共用同樣的L2 Cache與Memory Management,因此當Linux Kernel在上面運作時,包括4GB的記憶體分頁,應用程式的多工執行環境,就能在有開啟Linux Kernel CPU Up/Down HotPlug的機制下無縫銜接,且上面運作的Task能跨不同的處理器進行Task Migration,無需解決跨到不同處理器與映射到不同記憶體空間的複雜問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
談到這,不論是aSMP或是vSMP都有其擁護者,並能充分發揮Linux Kernel CPU Up/Down HotPlug的特性,也都各自具備相當的發展潛力. 但要能讓這樣的設計充分發揮效益,還有一些在核心與排程機制上,需要優化的空間. 以目前Linux Kernel的Tasks排程機制實作來說,並沒有考慮到每個處理器具備不同運算能力的條件,就算是對處理器有Load Weight的計算,也是以該處理器所負荷的排程單元Load Weight來做統計,只能反映出哪個處理器目前排程單元的負荷,但並不能根據個別處理器的效能,而給予合理的排程負荷計算參數. 因此,如果有一個aSMP架構的處理器動態把時脈降低,而這處理器又跟其他運算能力較高的處理器一起進行Tasks排程,就有可能讓重要的Task被放到運算能力較低,且當下負荷又已經過重的處理器上執行,而導致在產品端的執行效果不如預期.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文,會把焦點放在排程機制的介紹上,有關產品上的實作與技術問題,開發者可以根據自己所面對的平台與對於核心排程技術的了解,來進行設計. 本文主要參考的Linux核心有 2.6.10, 2.6.38.6 與 3.0.4,但由於Linux核心仍在持續的演進中,若你使用的版本跟筆者不同,還請以你手中的Linux Kernel Source Code為依據. 最後,所有的內容筆者會盡力確保資訊的正確性,若有不足之處,還請不吝指教.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Linux Kernel </strong><strong>的排程機制</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,在linux Kernel 2.4 時,多核心的架構下是共用同一個Task Queue,且採用O(N)排程算法,在排程效率與對多核心的支援是相對較弱的.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE97CwyAOIWP7Mx7hU7pyPWAZHxFaBs-Yrn4Lk-MPUQSBn4FVVFy9MuUiikDTOaaNlZwBZYWX8Jop1wALs_hxb5gYsFj2lZ19IvoJNrQFK74qv_apVUikuBpERAtEbEg37mMhk0qBL-rs/s1600/image001%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="400" data-original-width="707" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE97CwyAOIWP7Mx7hU7pyPWAZHxFaBs-Yrn4Lk-MPUQSBn4FVVFy9MuUiikDTOaaNlZwBZYWX8Jop1wALs_hxb5gYsFj2lZ19IvoJNrQFK74qv_apVUikuBpERAtEbEg37mMhk0qBL-rs/s1600/image001%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">在linux Kernel 2.6 時,每個處理器都有兩個Task Queue,當位於Active Task Queue的行程執行完畢,就會依據行程的優先級,計算Priority與Time Slice,然後放到Expired Task Queue中,當Active Task Queue執行完畢後,就會Switch這兩個Task Queue,讓經過計算後的新Active Task Queue可以立刻加入排程.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipO7-sVVmLDnpS1LDsvZzHjcGemef_ErXvfvVHZjIq5ooEMXpuklBx_9IqPjyXHrImhn-8Gjry7fgJlL9ZV85xQIhxyS7CwQsGSCw3DIp-xpb-RPF7512yJxw7D3xqofL_QVPDyaPN9Ks/s1600/image002%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="470" data-original-width="715" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipO7-sVVmLDnpS1LDsvZzHjcGemef_ErXvfvVHZjIq5ooEMXpuklBx_9IqPjyXHrImhn-8Gjry7fgJlL9ZV85xQIhxyS7CwQsGSCw3DIp-xpb-RPF7512yJxw7D3xqofL_QVPDyaPN9Ks/s1600/image002%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此時Linux Kernel的核心排程採用的是 O(1)排程算法,我們可以參考Linux Kernel 2.6.10的原始碼,首先,依據O(1)的概念,Task Struct(如下所示)中的run_list會以Link List方式把同一個Task Priority 的行程串起來.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct task_struct {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct thread_info *thread_info;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
atomic_t usage;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long flags; /* per process flags, defined below */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long ptrace;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int lock_depth; /* Lock depth */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int prio, static_prio;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct list_head run_list;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而結構list_head的宣告如下所示,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct list_head {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct list_head *next, *prev;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在每個Task被產生時,會透過巨集INIT_LIST_HEAD初始化Task的run_list,把Link List的頭尾 next/prev都指向自己,而在Task被排入執行時就會透過函式enqueue_task執行巨集list_add_tail把Task的Link List放到對應的Priority Link List 結尾,而在Task被移出執行時,就會透過函式dequeue_task執行巨集list_del,把Task的Link List從對應的Priority Link List移出. 執行的概念如下圖所示,</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNj1wkYQhYRzcDyyfimlyPsScPbOBXatrnw_sQ2Q1h6OwqT1vPif0L82bf3cV5ErtKfPYOP2IvCTp87jvOIdY_Py34et82FihPgR8CzjJx-kz_PlDkv0I0fAqdpLsOjWLsMDXnHiWmuFM/s1600/image003%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="82" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNj1wkYQhYRzcDyyfimlyPsScPbOBXatrnw_sQ2Q1h6OwqT1vPif0L82bf3cV5ErtKfPYOP2IvCTp87jvOIdY_Py34et82FihPgR8CzjJx-kz_PlDkv0I0fAqdpLsOjWLsMDXnHiWmuFM/s1600/image003%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對同一個Task Priority來說,被排定執行的Task就會透過 run_list Link List串連起來,依序執行,並且在移除執行時,從Link List Node中移出.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考kernel/sched.c中的原始碼, Priority Array會根據目前140個Priority層級 (MAX_PRIO=140),幫每個Task Priority都配置一個Link List的 Queue Head,並且用unsigned long針對這140個Priority層級,透過Bits為0或1,來表示該Task Priority層級是否有需要被執行的Task在排程等待執行中,相關代碼如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define BITMAP_SIZE ((((MAX_PRIO+1+7)/8)+sizeof(long)-1)/sizeof(long))</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct prio_array {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned int nr_active;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long bitmap[BITMAP_SIZE];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct list_head queue[MAX_PRIO];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,以目前140bits的Task Priroty來說,會透過五個unsigned long,來表示完整的140bits.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFO0sRyfwFKJw0OIl5KI_4rqIyLWiqivpEU_RYLrIdUK4IYNNl-ZGzRd7sAl2LA3JMqWwTpPqOMukb8gsmVrQP3UUEBCvOAp-aYwuEKBPZTKzjKTqeqTU-mBqj2-XJvt-ifAdAXWehR9E/s1600/image004%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="148" data-original-width="720" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFO0sRyfwFKJw0OIl5KI_4rqIyLWiqivpEU_RYLrIdUK4IYNNl-ZGzRd7sAl2LA3JMqWwTpPqOMukb8gsmVrQP3UUEBCvOAp-aYwuEKBPZTKzjKTqeqTU-mBqj2-XJvt-ifAdAXWehR9E/s1600/image004%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行時期,再透過巨集sched_find_first_bit (這部份會依據平台以處理器優化的指令集來處理),針對這140bits,找出第一個目前有Task在其中等待執行的Task Priority.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
整體運作的概念,如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCebCh1QtCH0AIfejrE_GqsvWWPo6MqunSI65yLklT3VMBs7xsfvzAxn1PnA6yiXf7eSFuymSeBZBJEKfzceubgXX8O_ykhA7SFZFBvTdgfxxqt5dg4R-VXizGRhh23AfayYoXo33rRws/s1600/image005%255B1%255D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="472" data-original-width="760" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCebCh1QtCH0AIfejrE_GqsvWWPo6MqunSI65yLklT3VMBs7xsfvzAxn1PnA6yiXf7eSFuymSeBZBJEKfzceubgXX8O_ykhA7SFZFBvTdgfxxqt5dg4R-VXizGRhh23AfayYoXo33rRws/s1600/image005%255B1%255D.jpg" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
雖然有了O(1)的實作,而且基於這實作,也確實可以很快讓排程機制很有效率的運作,然而處理器雖然是具備多工的能力,但真實的情況下,一個處理器同一時間只能執行一個Task,也就是說,在不考慮觸發中斷與重新觸發排程機制的情況下,在當前Task的Time Slice尚未執行完畢前,其他的Task是沒有機會被執行的. 也因此,在Linux Kernel 2.6.23之後,Linux核心採用了新的 CFS(Completely Fair Scheduler)排程機制(作者為Ingo Molnar),希望可以基於排程的改善,盡可能的讓每個不同等級的Task可以更公平的分配到處理器的時間,基於RB Tree的概念,可以讓越少被執行到的Task,有更高的優先機率被處理器執行到,避免優先級較低的Task,被延遲較久的時間才得到被處理器執行的機會.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Linux Kernel 3.0.4中有關CFS的Design文件 (路徑在Documentation/scheduler/sched-design-CFS.txt),作者試著用一句 “CFS basically models an “ideal, precise multi-tasking CPU” on real hardware.” 來簡要說明CFS 80%設計精神 .所謂理想的多工處理器,就是當處理器有100%的能力,且系統中有兩個Tasks正在運作,這兩個Tasks可以各自取得處理器50%的執行能力,並被處理器平行執行,也就是說任意時間間隔來看(例如,隨機取10ms間隔),這兩個Tasks都是分配到處理器50%的執行能力.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以實際的處理器運作行為來說,一個處理器同一時間只能執行一個Task,當這個Task Time-Slice結束後,會透過Context-Switch切換下一個Task進來執行,當系統中的Tasks個數便多時,在特定的時間間隔來看,處理器等於執行特定Task的時間較長,而對於優先級較低的Task,卻可能在該區間中都沒有得到執行權. 換個角度來說,Tasks有優先級也有Time Slice長度的區別,假設Task #A Time Slice長度為10ms,以總Tasks數量與總Time Slice長度來說,會取得處理器5%的執行時間,最理想的狀況是,我們在任意一秒的間隔來看,Task#A都可以分到處理器5%的執行時間,但在現實的狀況來說,在任意一秒的間隔來看,只要有優先級高的Task被排程到,且該Task分配到的Time Slice較長,就會讓Task#A呈現在一個不公平的時間分配中. 雖然,用較長的時間來看一定是公平的,但CFS希望解決的就是讓目前處理器執行的機制上,可以盡可能的做到即時的公平.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因此,CFS導入了”Virtual Runtime”的概念(單位為nanosec),根據目前總共的Tasks數量,用以作為選擇下一個執行Task Time Slice的依據.例如,CFS會選擇目前p->se.vruntime值最低的Task來執行(也就是距離上一次被執行時間間隔最久的Task),會在每一次觸動排程機制時,盡可能的達到”理想的多工處理器”的目標.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然而,在實際Linux Kernel的Time Slice與Priority來看,CFS的概念還必須要考慮到依據每個Task的Nice Value所計算的Time Slice長度不一定每個Task都一切,而且每個Task的Real-Time Priority值也不盡相同,有關Task 計算Time Slice與Real-Time Priority的說明,會另外在下一段文章中介紹.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>每次</strong><strong>Scheduler Tick</strong><strong>觸發時</strong><strong>,</strong><strong>所進行的動作</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
不論是O(N),O(1)與CFS,系統的排程都是基於固定的Scheduling Tick來觸發,也因此,每一次的Scheduling Tick觸發,都攸關Task執行的週期與是否要進行Task的切換,也是排程機制核心的部分.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel的Scheduling機制,會根據編譯核心時配置的HZ值來決定,一般來說是每1/100秒或每1/1000秒觸發一次Scheduling Tick,讓系統的排程機制可以去計算每個Task執行的時間,並藉此決定是不是要進行Task Context-Switch.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以支援CFS的Linux Kernel 2.6.38.6來說,每次觸發Scheduling Tick都會執行下述的動作</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,取得目前的CPU ID,與目前CPU的 RunQueue指標,與目前RunQueue中正在執行的Curr Task指標</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫 sched_clock_tick (實作在kernel/sched_clock.c中),這函式需在有設定Unstable CPU Clock時才有作用,如果全域變數sched_clock_stable為1,這個函式就會不作用直接返回.(ARM環境中,這個變數並無作用.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,取得 RunQueue SpinLock</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,呼叫update_rq_clock (實作在kernel/sched.c中), 若runQueue沒有設定skip_clock_update,這函式會更新RunQueue的Clock值.並呼叫函式update_rq_clock_task, 更新RunQueue clock_task值,clock_task會把前後兩次RunQueue Clock的Delta值,減去處理器進行Soft-IRQ與Hardware-IRQ的時間差值後,對clock_task進行累加. 可用以反應出RunQueue中Task實際被處理器執行的時間累加值.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,呼叫update_cpu_load_active,會透過函式update_cpu_load在每次Tick觸發時,更新RunQueue cpu_load Array,用以反應目前RunQueue所在的處理器負載.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,執行目前Task 所在Class的Tick函式(ex, curr->sched_class->task_tick),若Current Task是屬於Fair Class,就會呼叫task_tick_fair (實作在kernel/sched_fair.c中). 依序若Current Task為Stop/Real-Time/Idle Scheduling Class就會呼叫函式 task_tick_stop/ task_tick_rt/ task_tick_idle.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,釋放RunQueue SpinLock</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,呼叫perf_event_task_tick (若編譯時,沒設定CONFIG_PERF_EVENTS,這函式會是inline的空函式),主要用以支援核心處理器效能的監聽動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9,在SMP架構下,會呼叫函式idle_cpu,用以更新RunQueue的idle_at_tick值,為1表示目前CPU RunQueue執行的是Idle Task,反之為0,則非Idle Task. 可供判斷目前這RunQueue所在處理器是否處於閒置的狀態.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10,在SMP架構下,會呼叫trigger_load_balance, 若已達到RunQueue設定下一次觸發Load Balance的jiffies時間值(next_balance),就會觸發Scheduling Softare IRQ,並在Software IRQ中透過函式rebalance_domains,執行Scheduling Domain Load Balance動作.若未達RunQueue下一次觸發Load Balance的jiffies時間值,且在編譯核心時有設定CONFIG_NO_HZ (NO HZ可支援處理器執行Idle Task時,停止系統的Scheduling Tick,可在進入pm_idle時,減少Timer中斷觸發(例如HZ=100,每秒就有一百次Tick Timer中斷觸發),減少系統被觸發醒來的機會.),就會呼叫函式nohz_balancer_kick,Kick一個處理器進行No Hz Load Balance.被Kick選擇為進行No Hz Load Balance的處理器所屬RunQueue的nohz_balance_kick值會設定為1.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以上總結每次觸發Scheduling Tick時,主要進行的工作內容.接下來我們再透過pick_next_task,看在目前系統支援四種Scheduling Class的排程下,一個Task是如何被撿選出來執行的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>從</strong><strong>pick_next_task</strong><strong>看</strong><strong>Scheduling Class</strong><strong>對排程的影響</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
檢視CFS對不同Scheduling Class行為最好的入口就是函式pick_next_task (實作在 kernel/sched.c中),在函式pick_next_task中會執行如下的流程找到下一個要被載入執行的Task</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,檢查目前總Runnable Task數量是否跟放在Fair Class中的數量一致 (rq->nr_running == rq->cfs.nr_running),若成立,就執行執行Fair Scheduling Class的pick_next_task抓取下一個執行的Task</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,若1不成立,就會執行 for_each_class(class) {….}迴圈,可以參考如下define宣告</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define sched_class_highest (&stop_sched_class)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define for_each_class(class) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
for (class = sched_class_highest; class; class = class->next)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前優先級最高的Scheduling Class為 Stop-Task Scheduling Class,而在函式pick_next_task中,就會依序執行 Stop-Task, Real-Time,Fair 與 Idle-Task Scheduling Class所實作的pick_next_task函式,先找到的Task就會由函式pick_next_task回傳. 也因此,當有Task存在 Stop-Task或是Real-Time Scheduling Class中時,這時屬於Fair Scheduling Class中的Task執行的優先級就會降低.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
總結運作的概念,可以參考下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidfuduRgOCIr1v1vwzMTl8cm-D8800ePK4leQV4ICrwxvQP8bDMCX9-8GUH1k92nzQylhUl_gfGXQMdaxRQTDhnImOIbwBLAFrm_-dRl6lNtBWejFgM3Kgm6Y_f-5U2oioMM7e5RQuipM/s1600/image006%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="236" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidfuduRgOCIr1v1vwzMTl8cm-D8800ePK4leQV4ICrwxvQP8bDMCX9-8GUH1k92nzQylhUl_gfGXQMdaxRQTDhnImOIbwBLAFrm_-dRl6lNtBWejFgM3Kgm6Y_f-5U2oioMM7e5RQuipM/s1600/image006%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CSF RBTREE(Red-Black Tree) – O(Log</strong><strong>2(</strong><strong>N</strong><strong>)</strong><strong>)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CFS挑選Task的機制為RB-Tree,概念如下圖所示,包括Task或是Task Group,都會是RBTree中的一個Node支點,每次選擇Task來執行時,都會選擇左邊目前Virtual RunTime最低的Task(也就是最久沒有被執行到的Task)來執行,雖然Virtual RunTime會根據Task的Priority而有增長的差異,例如:Nice Priority低的Task Virutal RunTime會增長的比較快,相對佔據處理器執行的時間就會比較短,反之,Nice Priority 高的Task會因為Virutal RunTime增長的慢,而得到相對比較多實際的處理器執行時間. 但在理想的情況下,如果大家都是Nice 0的情況,基於CFS RBTree的機制,可以讓多數的Task能相對均勻的得到處理器的執行時間,而避免有特定的Task等待比較久的時間沒有得到處理器的執行機會.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0uuLGtjbjv453EWoqjrSqe9ZjYQCQBOr6tONb5_BFtZEeYW79UlklIHZecznP0imzda_xgqZeTChgm2X_xUBI0EC7jSysMpKO1zcgH7vK2_4C-tJOE9ALqZfWpuMzg4KiJBg8kwife6A/s1600/image007%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="332" data-original-width="717" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0uuLGtjbjv453EWoqjrSqe9ZjYQCQBOr6tONb5_BFtZEeYW79UlklIHZecznP0imzda_xgqZeTChgm2X_xUBI0EC7jSysMpKO1zcgH7vK2_4C-tJOE9ALqZfWpuMzg4KiJBg8kwife6A/s1600/image007%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對CFS與RBTree建立基本的概念後,接下來讓我們進一步的探討處理器排程RunQueue的資料結構,更清楚的掌握排程運作的內涵.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>處理器的</strong><strong>RunQueue</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在目前的Linux Kernel中,每個處理器都會配置一個RunQueue,而從了解RunQueue的資料結構著手,我們能對排程的運作有更清楚的藍圖,進而在程式碼的閱讀上,可以更加清晰. 在本節,筆者會把RunQueue的資料結構struct rq (宣告在 kernel/sched.c中)進行介紹,讓各位可以知道核心排程是基於哪些參數進行運作,這參數的內容比較繁瑣,建議可以先有個概念,若有興趣進一步探究的,再回到本節即可.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,處理器RunQueue主要包含以下的參數與對應的說明</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">參數名稱</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">說明</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">raw_spinlock_t lock</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以作為RunQueue的SpinLock</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long nr_running</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以記錄目前處理器RunQueue中執行的Task數量</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long cpu_load[]</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">cpu_load主要用以表示處理器的負載,目前這個Array大小為5 (定義在CPU_LOAD_IDX_MAX),在每個處理器的RunQueue中都會有對應到該處理器的cpu_load參數配置,在每次處理器觸發Scheduler Tick時, 都會呼叫函式update_cpu_load_active,進行cpu_load的更新.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在系統初始化時,會呼叫函式sched_init把RunQueue的cpu_load Array初始化為0.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
了解cpu_load Array更新最好的方式應該是透過函式update_cpu_load (實作在kernel/sched.c),基於這函式的實作,我們可以把cpu_load Array每個數值公式說明如下.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_load[0]會直接等於RunQueue中load.weight的值.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_load[1]=(cpu_load[1]*(2-1)+cpu_load[0])/2</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_load[2]=(cpu_load[2]*(4-1)+cpu_load[0])/4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_load[3]=(cpu_load[3]*(8-1)+cpu_load[0])/8</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_load[4]=(cpu_load[4]*(16-1)+cpu_load[0])/16</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當呼叫函式this_cpu_load時,所傳回的 CPU Load值是cpu_load[0] (也就是會等於RunQueue中的load.weight).而在進行CPU Blance或Migration時,就會呼叫函式source_load與target_load取得對應處理器與對應cpu_load index值,來進行計算.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long last_load_update_tick</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以記錄最後一次更新CPU Load的時間值. (會把當時的jiffies值儲存到這變數).</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805"><strong>ifdef CONFIG_NO_HZ</strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 nohz_stamp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">在linux Kerel 2.6.38.6中,這個參數沒有作用.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned char nohz_balance_kick</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">初始值為0,用在當NO Hz機制有開啟時的CFS Fair Scheduling的Load Balance機制.可參考kernel/sched_fair.c 中的函式trigger_load_balance實作.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在SMP架構下,且有設置NO HZ時,會在每次Scheduling Tick觸發時,由函式scheduler_tick(in kernel/sched.c)呼叫trigger_load_balance,再呼叫函式nohz_balancer_kick,Kick一個處理器進行No Hz Load Balance.而被選擇進行No Hz Load Balance工作處理器的RunQueue中的nohz_balance_kick數值會設定為1.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned int skip_clock_update</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">如果skip_clock_update的值被設定為1,此時透過函式update_rq_clock要進行RunQueue Clock值的更新時,就會直接返回.(每次呼叫update_rq_clock函式,都會讓RunQueue中的Clock值等於sched_clock_cpu的返回值.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct load_weight load</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">參考include/linux/sched.h中struct load_weight的宣告如下<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct load_weight {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long weight, inv_weight;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
RunQueue中的load->weight值,會是目前所執行的schedule entity的load->weight的總和,也就是說,RunQueue的load->weight越高,也表示所負責的排程單元load->weight總合越高,表示處理器所負荷的執行單元也越重.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long nr_load_updates</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">在每次Scheduler Tick中呼叫update_cpu_load時,這個值都會加一,可以用來反應目前CPU Load更新的次數.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 nr_switches</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用來累加處理器進行Context Switch的次數,會在函式schedule呼叫時進行累加,並可以透過函式nr_context_switches統計目前所有處理器總共的Context Switch次數. 或是可以透過查看檔案/proc/stat中的ctxt欄位得知目前整個系統觸發Context Switch的總數.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct cfs_rq cfs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">為CFS Fair Scheduling Class的 RunQueue</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct rt_rq rt</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">為Real-Time Scheduling Class的RunQueue</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">ifdef CONFIG_FAIR_GROUP_SCHED (用以支援可以Group CFS Tasks的機制.)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct list_head leaf_cfs_rq_list</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">在有設置Fair Group Scheduling的環境下,會基於原本CFS RunQueue與包含有若干Task的Group所成的排程集合,也就是說當有一個Group A,其下有20個Tasks,而這Group A就會有自己的CFS RunQueue用來排程自己所屬的Tasks,而屬於這Group A的Tasks所使用到的處理器時間,就會以這Group A總體所分得的時間為上限. 基於 Cgroup的 Fair Group Scheduling架構,可以創造出有階層性的Tasks組織,根據不同Tasks的功能群組化,在配置給該群組對應的處理器資源,讓屬於該群組下的Tasks可以透過RunQueue機制排程,使用屬於該群組所配置到的資源.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這個變數主要是用來管理CFS RunQueue List,操作上可以透過函式list_add_leaf_cfs_rq把一個Group CFS RunQueue加入到List中,或透過函式list_del_leaf_cfs_rq把一個Group CFS RunQueue移除. 並可透過for_each_leaf_cfs_rq把一個 RunQueue上的所有leaf cfs_rq走過一遍.</div>
</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">ifdef CONFIG_RT_GROUP_SCHED (用以支援可以Group Real-Time Tasks的機制.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct list_head leaf_rt_rq_list</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">類似於leaf_cfs_rq_list所扮演的角色,只是這是針對屬於Real-Time的Task,在實際操作上可以透過函式list_add_leaf_rt_rq,list_del_leaf_rt_rq或巨集for_each_leaf_rt_rq.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long nr_uninterruptible</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">一般來說,Linux Kernel的Task狀態可以為TASK_RUNNING, TASK_INTERRUPTIBLE (Sleep) , TASK_UNINTERRUPTIBLE (Deactivate Task,此時Task會從RunQueue移除)或TASK_STOPPED. (在此先忽略Trace,Zombie,Dead..etc). 透過這個變數會統計目前RunQueue中有多少Task屬於TASK_UNINTERRUPTIBLE的狀態.當呼叫函式activate_task時,會把nr_uninterruptible值減一,並透過函式enqueue_task把對應的Task依據所在的Scheduling Class放到對應的RunQueue中,並把目前RunQueue的nr_running值加一.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct task_struct *curr, *idle, *stop</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">為指向三個Task的指標. (Current Task,Idle Task與最高執行級的Stop Task).<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
curr : 指向目前處理器正在執行的Task</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
idle: 指向屬於Idle-Task Scheduling Class的Idle Task.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
stop: 指向目前最高等級屬於 Stop-Task Scheduling Class的Task</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long next_balance</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">基於處理器的jiffies值,用以記錄下次進行處理器Balancing的時間點.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct mm_struct *prev_mm</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以儲存Context-Switch發生時,前一個Task的Memory Management結構,並可用在函式finish_task_switch中,透過函式mmdrop釋放前一個Task的記憶體資源.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 clock</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以記錄目前RunQueue的Clock值,基本上該值會等於透過sched_clock_cpu(cpu_of(rq))的回傳值,並會在每次呼叫scheduler_tick時透過函式update_rq_clock更新目前RunQueue clock值.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在實作部分,函式sched_clock_cpu會透過sched_clock_local或ched_clock_remote取得對應的sched_clock_data,而處理器的sched_clock_data值,會透過函式sched_clock_tick在每次呼叫scheduler_tick時進行更新.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
補充….</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從函式update_rq_clock的實作來說,其實</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
delta = sched_clock_cpu(cpu_of(rq)) – rq->clock;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
rq->clock += delta;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以直接寫成</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
rq->clock= sched_clock_cpu(cpu_of(rq));</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 clock_task</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">這個值會等於從上一次更新RunQueue Clock時,到這次要更新RunQueue Clock時的時間間隔 Delta 減去在這段時間中,處理器用來進行Soft-IRQ與Hardware-IRQ的時間差值的累加.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡要來說,這個值會透過函式update_rq_clock_task進行更新,用來反應出RunQueue中Task實際執行時所佔用到的處理器時間Clock累加值.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">atomic_t nr_iowait</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以記錄目前RunQueue中有多少Task處於等待I/O的Sleep狀態.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在實際的使用上,例如當Driver接收來自Task的調用,但處於等待I/O回覆的階段時,為了充分利用處理器的執行資源,這時就可以在Driver中呼叫函式io_schedule,此時就會把目前RunQueue中的nr_iowait加一,並設定目前Task的in_iowait為1,然後觸發Scheduling讓其他Task有機會可以得到處理器執行時間.</div>
</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">ifdef CONFIG_SMP</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct root_domain *rd</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">Root Domain是基於多核心架構下的機制,會由RunQueue結構記住目前採用的Root Domain,其中包括了目前的CPU Mask(包括 Span, Online 與 RT Overload), Reference Count 跟cpupri.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當Root Domain有被RunQueue參考到時, refcount就會加一,反之就是減一. 而CPU Mask Span表示RunQueue可掛上的CPU Mask, Online為RunQueue目前已經掛上排程的CPU Mask,最後的RT Overload(rto_mask)代表的是這個RunQueue可在對應的rto_mask CPU上執行Real-Time Task. 可以參考檔案kernel/sched_rt.c中函式pull_rt_task的實作,當一個RunQueue中屬於Real-Time的Task已經執行完畢(也就是rq->rt.rt_nr_running==0),就會透過函式pull_rt_task從該RunQueue中屬於rto_mask CPU Mask可以執行的處理器上,找出是否有一個處理器有大於一個以上的Real-Time Task,若有就會轉到目前這個執行完畢Real-Time Task的處理器上.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而cpupri不同於Task本身有區分140個(0-139)Task Priority (0-99為RT Priority 而 100-139為Nice值 -20-19). CPU Priority本身有102個Priority (包括,-1 為Invalid,0為Idle,1為Normal,2-101對應到Real-Time Priority 0-99).參考函式convert_prio, Task Priority如果是 140就會對應到CPU Idle,如果是大於等於100就會對應到CPU Normal,若是Task Priority介於0-99之間,就會對應到CPU Real-Time Priority 101-2之間.) 在實際的操作上,例如可以透過函式cpupri_find帶入一個要插入的Real-Time Task,此時就會依據cpupri中pri_to_cpu選擇一個目前執行Real-Time Task且該Task的優先級比目前要插入的Task更低的處理器,並透過CPU Mask(lowest_mask)返回目前可以選擇的處理器Mask.實作的部份可以參考檔案kernel/sched_cpupri.c.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在初始化的過程中,會透過函式sched_init呼叫函式init_defrootdomain,對Root Domain與 CPU Priority機制進行初始化.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct sched_domain *sd</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">Schedule Domain是基於多核心架構下的機制.每個處理器都會有一個基礎的Scheduling Domain, Scheduling Domain可以有階層性的架構,透過parent可以找到上一層的Domain,或是透過child找到下一層的 Domain (NULL表示結尾.).並可透過span欄位,表示這個Domain所能涵蓋的處理器範圍. 通常Base Domain會涵蓋系統中所有處理器的個數,而Child Domain所能涵蓋的處理器個數不超過它的Parent Domain. 而當在進行Scheduling Domain 中的Task Balance時,就會以該Domain所能涵蓋的處理器為最大範圍.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
同時,每個Schedule Domain都會包括一個或一個以上的CPU Groups (結構為struct sched_group),並透過next變數把CPU Groups串連在一起(成為一個單向的Circular linked list),每個CPU Group都會有變數cpumask來定義這個CPU Group所涵蓋的處理器範圍.並且CPU Group所包括的處理器範圍,必需涵蓋在所屬的Schedule Domain處理器範圍中.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當進行Scheduling Domain的Balancing時,會以其下的CPU Groups為單位,根據cpu_power (會是該Group所涵蓋的處理器Tasks Loading的總和)來比較不同的CPU Groups的負荷,以進行Tasks的移動,達到Balancing的目的.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在有支援SMP的架構下,會在函式sched_init中,呼叫open_softirq,註冊 SCHED_SOFTIRQ Software IRQ與其對應的 Callback函式 run_rebalance_domains. 並會在每次呼叫函式scheduler_tick時,透過函式trigger_load_balance確認是否目前的jiffies值已經大於RunQueue下一次要觸發Load Balance的next_balance時間值,並透過函式raise_softirq觸發SCHED_SOFTIRQ Software IRQ. 在Software IRQ觸發後,就會呼叫函式run_rebalance_domains,並在函式rebalance_domains中,進行後續處理器上的Scheduling Domain Load Balance動作.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Scheduling Domain進一步的內容,也可以參考Linux Kernel文件 Documentation/scheduler/sched-domains.txt.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long cpu_power</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">在SMP架構下,這值可用以表示目前RunQueue所在處理器的計算能力,在函式sched_init初始化時,會把這值設定為SCHED_LOAD_SCALE (=Nice 0的Load Weight=1024).並可透過函式update_cpu_power (in kernel/sched_fair.c)更新這個值.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
處理器的CPU Power值越大,表示這個處理器有更多的計算能力,可以分擔CPU Power值越小的處理器上的Tasks任務.</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned char idle_at_tick</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">這值會等於函式idle_cpu的返回值,如果為1表示目前CPU RunQueue中執行的為Idle Task. 反之為0,則表示處理器執行的不是Idle Task (也就是說處理器正在忙碌中.).</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">int post_schedule</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">若這值不為0,表示會有在Schedule排程動作結束前,要呼叫的收尾函式. (實作為inline函式post_schedule in kernel/sched.c),目前只有Real-Time Scheduling Class有支援這個機制(會呼叫函式has_pushable_tasks in kernel/sched_rt.c).</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">int active_balance</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">當RunQueue中此值為1,表示這個RunQueue正在進行Fair Scheduling的Load Balance,此時會呼叫stop_one_cpu_nowait暫停該RunQueue所屬處理器的排程,並透過函式active_load_balance_cpu_stop,把Tasks從最忙碌的處理器,移到Idle的處理器上執行.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">int push_cpu</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以儲存目前進入Idle且負責進行 Load Balance流程的處理器ID. 呼叫的流程為,在呼叫函式schedule時,若該處理器RunQueue的nr_running為0 (也就是目前沒有正在執行的Task),就會呼叫idle_balance,並觸發後續Load Balance流程.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct cpu_stop_work active_balance_work</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以儲存給Stopper Scheduling Class所要執行的函式與其對應參數. 會作為在函式stop_one_cpu_nowait中呼叫函式cpu_stop_queue_work的參數.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">int cpu</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以儲存目前運作這個RunQueue的處理器ID.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">int online</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">為1表示目前此RunQueue有在對應的處理器掛上並執行.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long avg_load_per_task</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">如果RunQueue中目前有Task正在執行,這個值會等於目前該RunQueue的Load Weight除以目前RunQueue中Task數目的均值. (rq->avg_load_per_task = rq->load.weight / nr_running;).</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 rt_avg</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">這個值會由Real-Time Scheduling Class呼叫函式update_curr_rt,用以統計目前Real-Time Task執行時間的均值,在這函式中會以目前RunQueue的clock_task減去目前Task執行的起始時間,取得執行時間的Delta值. (delta_exec = rq->clock_task – curr->se.exec_start; ). 在透過函式sched_rt_avg_update把這Delta值跟原本RunQueue中的rt_avg值取平均值. 以運作的週期來看,這個值可反應目前系統中Real-Time Task平均被分配到的執行時間值.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 age_stamp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">這個值主要在函式sched_avg_update更新,以筆者手中的Linux Kernel 2.6.38.6的實作來說,當RunQueue Clock減去age_stamp大於 0.5秒 (=sched_avg_period),就會把這值累加0.5秒 (單位都是nanoseconds). 從函式scale_rt_power的實作來說,age_stamp值離RunQueue Clock越遠,表示total值越大,available值也越大,而函式scale_rt_power返回的div_u64計算結果也越大,最終 RunQueue的cpu_power與Scheduling Domain中的Scheduling Group的cpu_power值也就越大. (可參考函式update_cpu_power的實作).</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 idle_stamp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">這值會在觸發Scheduling時,若判斷目前處理器RunQueue沒有正在運作的Task,就會透過函式idle_balance更新這值為為目前RunQueue的clock值.可用以表示這個處理器是何時進入到Idle的狀態.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 avg_idle</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">會在有Task運作且idle_stamp不為0 (表示前一個狀態是在Idle)時以目前RunQueue的clock減去idle_stamp所計算出的Delta值為依據,更新這個值. 可反應目前處理器進入Idle狀態的時間長短.</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">ifdef CONFIG_IRQ_TIME_ACCOUNTING</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">u64 prev_irq_time</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">這值會透過函式update_rq_clock_task更新,可用以代表處理器執行Soft-IRQ與Hardware-IRQ所花的處理器Clock值的累加.s</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long calc_load_update</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以記錄下一次計算CPU Load的時間,初始值為目前的jiffies加上五秒與1次的Scheduling Tick的間隔 (=jiffies + LOAD_FREQ,且LOAD_FREQ=(5*HZ+1))</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">long calc_load_active</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">會等於RunQueue中nr_running與nr_uninterruptible的總和.(可參考函式calc_load_fold_active).</td></tr>
<tr class=""><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">ifdef CONFIG_SCHED_HRTICK</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">ifdef CONFIG_SMP</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">int hrtick_csd_pending</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">在函式init_rq_hrtick初始化RunQueue High-Resolution Tick時,此值預設為0.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在函式hrtick_start中,會判斷目前觸發的RunQueue跟目前處理器所使用的RunQueue是否一致,若是,就直接呼叫函式hrtimer_restart,反之就會依據RunQueue中hrtick_csd_pending的值,如果hrtick_csd_pending為0,就會透過函式__smp_call_function_single讓RunQueue所在的另一個處理器執行rq->hrtick_csd.func 所指到的函式 __hrtick_start. 並等待該處理器執行完畢後,才重新把hrtick_csd_pending設定為1.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也就是說, RunQueue的hrtick_csd_pending是用來作為SMP架構下,由處理器A觸發處理器B執行_hrtick_start函式的一個保護機制.而有關在SMP下如何由一個處理器觸發另一個處理器執行函式的機制,可以參考kernel/smp.c中相關smp_call_function_xxxxxxx的實作.s</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct call_single_data hrtick_csd</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以儲存hrtick機制中,要跨處理器執行的函式結構.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct hrtimer hrtick_timer</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">為High-Resolution Tick的結構,會透過函式hrtimer_init初始化.</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="805">ifdef CONFIG_SCHEDSTATS</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">struct sched_info rq_sched_info</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">為Scheduling Info.的統計結構,可以參考include/linux/sched.h中的宣告. 例如在每次觸發Schedule時,呼叫函式schedule_debug對上一個Task的lock_depth進行確認(Fork一個新的Process 時,會把此值預設為-1就是No-Lock,當呼叫Kernel Lock時, 就會把Current Task的lock_depth加一.),若lock_depth>=0,就會累加Scheduling Info.的bkl_count值,用以代表Task Blocking的次數.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned long long rq_cpu_time</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">可用以表示RunQueue中的Task所得到CPU執行時間的累加值.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在發生Task Switch時,會透過sched_info_switch呼叫sched_info_arrive並以目前RunQueue Clock值更新Task 的sched_info.last_arrival時間,而在Task所分配時間結束後,會在函式sched_info_depart中以現在的RunQueue Clock值減去Task的sched_info.last_arrival時間值,得到的 Delta作為變數rq_cpu_time的累加值.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned int yld_count</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以統計呼叫System Call sys_sched_yield的次數.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned int sched_count</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">可用以統計觸發Scheduling的次數. 在每次觸發Scheduling時,會透過函式schedule呼叫schedule_debug,呼叫schedstat_inc對這變數進行累加.</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned int sched_goidle</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">可用以統計進入到Idle Task的次數. 會在函式pick_next_task_idle中,呼叫schedstat_inc對這變數進行累加.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned int ttwu_count</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以統計Wake Up Task的次數.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">unsigned int ttwu_local</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555">用以統計Wake Up 同一個處理器Task的次數.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="555"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
至此,有關RunQueue的結構說明告一段落.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CFS</strong><strong>的</strong><strong>Scheduling Classes </strong><strong>與</strong><strong> Scheduling Policies</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CFS排程機制在設計時,考慮到排程機制的彈性,定義了Scheduler Class的機制,讓排程機制可以根據設計的需求,延伸不同的排程模組進來,每個新加入的排程機制都必須要提供Scheduler Class的實作,結構為 struct sched_class (定義在檔案include/linux/sched.h中). 舉sched_fair.c的實作來說, Scheduler Class實作的宣告如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="806"><strong>static const struct sched_class fair_sched_class = {</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.next = &idle_sched_class,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.enqueue_task = enqueue_task_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.dequeue_task = dequeue_task_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.yield_task = yield_task_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.check_preempt_curr = check_preempt_wakeup,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.pick_next_task = pick_next_task_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.put_prev_task = put_prev_task_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#ifdef CONFIG_SMP</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.select_task_rq = select_task_rq_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.rq_online = rq_online_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.rq_offline = rq_offline_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.task_waking = task_waking_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#endif</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.set_curr_task = set_curr_task_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.task_tick = task_tick_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.task_fork = task_fork_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.prio_changed = prio_changed_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.switched_to = switched_to_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.get_rr_interval = get_rr_interval_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#ifdef CONFIG_FAIR_GROUP_SCHED</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>.task_move_group = task_move_group_fair,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#endif</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>};</strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中相關函式的行為簡述如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">函式名稱</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">next</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">會指向下一個Scheduling Class,以筆者所採用的Linux Kernel 2.6.38.6而言,Scheduling Class的順序為<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
stop_sched_class->rt_sched_class->fair_sched_class->idle_sched_class</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">enqueue_task</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">當Task屬於Runnable狀態時,就會呼叫這個函式把Task配置到RunQueue RBTree中,進行排程動作,並呼叫inc_nr_running將RunQueue中nr_running的值加一.(nr_running用以代表目前RunQueue有多少Runnable Task進行排程)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">dequeue_task</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">當Task不需要執行時,就會呼叫這個函式把Task從RunQueue RBTree中移除,並呼叫dec_nr_running將RunQueue中nr_running的值減一.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">yield_task</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">用以暫停目前正在執行中的Task,如果sysctl_sched_compat_yield有設定,就會找出目前RBTree中最右邊的Task(也就是vrruntime最多的Task),讓目前Task的vrruntime值等於最右邊Task值的vrruntime加一(可參考:se->vruntime = rightmost->vruntime + 1),如此在下次排程觸發時就會透過函式put_prev_task把目前的Task放到RBTree的最右邊,也就等同於暫停Task,讓該Task下次被執行到的機會最低.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">check_preempt_curr</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">用以決定一個Task是否可以中斷目前正在運作的Task,取得執行權.以CFS本身的實作來說 (in sched_fair.c).如果想要取代目前Task的Task本身的Scheduling Policy為 Batch或是Idle時,會直接返回,不會用來取代目前正在執行中的Task.反之,如果目前正在執行中的Task的Scheduling Policy為Idle,就會直接由所傳入的Task取代目前正在執行的Task.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">pick_next_task</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">用以在排程觸發時,從RunQueue RBTree中,取出符合目前Scheduling邏輯的下一個要被執行的Task.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">put_prev_task</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">用以在排程觸發時,把上一個執行完畢的Task放到目前RunQueue RBTree中對應的位置.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">set_curr_task</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">這個函式用以改變Task目前所屬的Scheduling Class與改變Task Group.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">task_tick</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">這是Scheduler的 Timer Tick來源,系統中觸發的Scheduling Tick會呼叫這個函式 (看HZ設定多少,100就是每秒呼叫這函式100次,1000就是每秒呼叫這函式1000次),<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以讓排程機制可以決定哪些Task應該要配執行與哪些Task應該要被移出RunQueue.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="254">select_task_rq<br />(需在SMP架構下)</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="552">通常用在執行一個新的程序,或是WakeUp一個Task時,會根據目前SMP下每個處理器的負荷,決定Task是否要切換到另一個處理器的RunQueue去執行,執行時會返回最後目標處理器的值.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此外,在Linux Kernel SMP的架構下,還會支援如下的函式</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">函式名稱</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="557">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">pull_task</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="557">可用來把Task從一個RunQueue移到目前的RunQueue來,並設定Task會在目前處理器的RunQueue中執行.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="250">can_migrate_task</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="557">可用來判斷一個Task可否從另一個RunQueue移到目前的處理器來執行,並返回判斷值.(返回值0就是不適合移動,1則是表明適合移動).<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前有以下三種情況,會返回失敗.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,該Task的cpus_allowed bitmap沒有設定目前的處理器 (也就是說在 CPU BitMap中該Task沒有被設定可以在目前處理器上能被同意執行)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,目前的Task正在該RunQueue被執行中</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,透過函式task_hot,判斷目前的Task是否為該RunQueue與Scheduling Domain中被執行時間較長的Task,基於對目前執行中處理器Cache-Hot的考量,該Task也不會被同意可以移動到目前的處理器.(可以避免Cache Flush,與在新的處理器上要重新進行Cache的動作.)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關的巨集</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define this_rq() (&__get_cpu_var(runqueues))</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define task_rq(p) cpu_rq(task_cpu(p))</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define cpu_curr(cpu) (cpu_rq(cpu)->curr)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define raw_rq() (&__raw_get_cpu_var(runqueues))</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
sched_class Class中宣告的Method,就是要在Linux Kernel排程中新增一個Scheduler Class所要實作的內容,讓Linux Kernel可以根據不同行程的需求,調度這些在系統中有註冊的排程模組,讓系統可以達到預定的執行目標與行為.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以Linux Kernel 2.6.38來說,目前共支援4種Scheduler Class,包括</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,Fair Scheduler Class (實作在檔案 sched_fair.c中):</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前包括有</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1.a, SCHED_NORMAL (也稱為SCHED_OTHER): 主要用以排程一般目的的Task.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1.b, SCHED_BATCH: 主要用以讓Task可以延長執行的時間(Time Slice),減少被中斷發生Task Context-Switch的次數.藉此可以提高 Cache的利用率 (每次Context-Switch都會導致Cache-Flush). 比較適合用在固定週期執行的Batch Jobs任務主機上,而不適合用在需要使用者互動的產品 (會由於Task切換的延遲,而感覺到系統效能不佳或是反應太慢).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,Real-Time Scheduler Class (實作在檔案 sched_rt.c中):</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
支援Real-Time Task的排程,包括有SCHED_FIFO與SCHED_RR. (SCHED_RR task預設的 Time Slice長度為100 msecs.).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Idle Task Scheduler Class (實作在檔案 sched_idletask.c中):</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
支援SCHED_IDLE,為系統中的Idle Task排程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,Stop Scheduler Class (實作在檔案 sched_stoptask.c中):屬於 Stop-Task Scheduling Class的Task是屬於系統中最高權限的Task,會中斷所有任務的執行,並且不會被其他任務所中斷.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前系統中,Scheduling Class的優先級順序為 Stop-Task > Real-Time > Fair > Idle-Task,開發者可以根據自己的設計需求,來把所屬的Task配置到不同的Scheduling Class中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>在支援</strong><strong>Fair Group Scheduling</strong><strong>環境下</strong><strong>,</strong><strong>以</strong><strong>CGroup (Control Group) Scheduler</strong><strong>分配</strong><strong>Task</strong><strong>與</strong><strong>Group</strong><strong>的處理器執行時間</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Control Group 提供了Linux核心可以把Tasks進行整合/區分或是依據子Group進行分派的動作. 根據Control Group文件中的定義,一個CGroup可以關聯到屬於1或多組SubSystem中的多個Tasks. SubSystem主要是基於CGroup提供的Task Group機制,扮演類似資源管控的角色,用以設定調配每個Group使用資源的限制. 在支援Control Group的Linux Kernel中,每一個Task在系統中都會屬於一個CGroup與一個SubSystem,每一個SubSystem都會有一個系統設定的組態,並配置到對應的CGroup中. 每一個Hierarchy架構,都有一個屬於CGroup虛擬檔案系統的Instance參考.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在系統運作時,會有多個有從屬關係的Task Groups同時運作,每一個Hierarchy都會屬於這系統中所有Tasks的一部分. 使用者可以透過CGroup虛擬檔案系統中的目錄名稱產生或刪除對應的CGroup,並可以查詢哪個CGroup有Task被指派,或是列出對應CGroup中所有被指派的Task PIDs. 藉由CGroup的設計,還可支援基於使用者帳號(Account)的處理器資源調配目的.(包括可以限定能使用的處理器或是Memory Node.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考 include/linux/cgroup_subsys.h的實做,目前CGroup包括以下的SubSystem,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,cpuset (CONFIG_CPUSETS):用以限定指定的Tasks使用的CPU與Memory資源,有關cpuset的使用可以透過函式sched_setaffinity,sched_getaffinity,set_mempolicy,get_mempolicy,mbind. 例如下述的例子,可以由應用程式透過函式sched_setaffinity指定當應用程式執行時,所要使用的處理器編號.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="652">http://fred-zone.blogspot.com/2007/10/cpu.html<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdio.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <sched.h></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main(void) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_set_t cmask;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long len = sizeof(cmask);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__CPU_ZERO(&cmask); /* 初始化 cmask */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__CPU_SET(0, &cmask); /* 指定第一個處理器 */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* 設定自己由指定的處理器執行 */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (!sched_setaffinity(0, len, &cmask)) {</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Could not set cpu affinity for current process.\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
exit(1);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,cpu_cgroup (CONFIG_CGROUP_SCHED):這選項會支援Tasks能被群組(Group)化與依據設定切割群組佔用的處理器執行時間. 更進一步,還可以設定CONFIG_RT_GROUP_SCHED用以支援群組的 Real-Time排程 <strong>(</strong><strong>支援包括</strong><strong> SCHED_FIFO </strong><strong>與</strong><strong> SCHED_RR)</strong>. 與可以設定CONFIG_FAIR_GROUP_SCHED 用以支援群組的CFS排程機制<strong>(</strong><strong>支援包括</strong><strong>SCHED_NORMAL</strong><strong>與</strong><strong>SCHED_BATCH)</strong>.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,cpuacct (CONFIG_CGROUP_CPUACCT):這選項用以支援CPU Accounting Controller機制,透過CGroup機制群組Task,並依據使用者的帳號(Account)所產生的Task群組來劃分處理器的執行時間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,debug (CONFIG_CGROUP_DEBUG):用以支援CGroup的Debug機制,像是Task Reference Count等統計資訊.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其它SubSystem還包括 ns (CONFIG_CGROUP_NS),mem_cgroup (CONFIG_CGROUP_MEM_RES_CTLR),devices (CONFIG_CGROUP_DEVICE),freezer (CONFIG_CGROUP_FREEZER),net_cls (CONFIG_NET_CLS_CGROUP),blkio (CONFIG_BLK_CGROUP).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在一個基於CGroup FileSystem的 Task-Group機制下,會統籌100%的處理器資源. 所有的處理器支援會根據root_task_group與所屬的子Task-Group的 Weight (=se->load.weight)基於Fair-Scheduling機制來進行處理器資源的分配工作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉實際的例子來說,當root_task_group中有十個Tasks且每個Task的Weight值為1024,在root_task_group之下又有兩個子Task Groups且這兩個子Task Group的Weight也都為1024,此時這兩個子Task Group所分配到的處理資源為 1024 / (10*1024 + 1024 + 1024) = 8.33% .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以參考如下操作流程,產生一個驗證Control Group的目錄,並在其中產生cpu目錄,並掛起CPU與CGroup相關的Device Node.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost ~]# mkdir /cgroup</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost ~]# mount -t tmpfs cgroup_root /cgroup</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost ~]# mkdir /cgroup/cpu</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost ~]# mount -t cgroup -ocpu none /cgroup/cpu</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost ~]# ls /cgroup/cpu</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cgroup.clone_children</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cgroup.event_control</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cgroup.procs</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu.rt_period_us</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu.rt_runtime_us</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu.shares</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
notify_on_release</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
release_agent</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
tasks</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost ~]#</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以從tasks檔案看到目前處理器上所有執行的Task Process ID,並從cpu.shares知道目前處理器所分擔的CPU Load基數.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,我們透過Control Group產生 GroupA與GroupB兩個Task Group群組,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost cpu]# mkdir GroupA</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost cpu]# mkdir GroupB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然後透過設定 cpu.shares,把GroupA的cpu.shares設定為4096,GroupB的cpu.shares設定為1024,也就是說在實際執行上,屬於GroupA的Tasks會比 GroupB的Tasks多得到約4倍的實際處理器執行時間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost cpu]# echo 4096 > GroupA/cpu.shares</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost cpu]# echo 1024 > GroupB/cpu.shares</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來我們用如下的程式碼,分別編譯為GroupA與GroupB的執行檔名稱,兩者唯一的差異只在於讓printf顯示的字串各別表示出自己是由GroupA或 GroupB所吐出的內容而已.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#include <stdio.h></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#define PrintThreshold 0x10000000</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>int main()</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>{</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>int i,vCount;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>i=0;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>vCount=0;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>while(1)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>{</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>i++;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>if(i>PrintThreshold)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>{</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>i=0;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>vCount++;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>printf(“GroupA:%ld\n”,vCount);</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>return 0;</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行編譯好的GroupA與GroupB執行檔,兩者Process ID分別為 1738與 1739,然後把這兩個Process ID分別設定給我們已經設定好差距四倍處理器執行時間的兩個Control Group目錄下的檔案tasks.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost cpu]# echo 1738 > GroupA/tasks</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost cpu]# echo 1739 > GroupB/tasks</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以透過top 指令查看這兩個程式執行時各自所佔的CPU比率與兩者的差距,如下所示,GroupA佔據處理器約80.6%的執行時間而GroupB佔據處理器約19.9%的執行時間. (兩者相加為100.5%,超過100%,但這是筆者環境中top的真實結果(或該說誤差),在此就不作討論),以比率來說兩者所佔CPU實際執行時間差距大約也是四倍,符合我們透過Control Group對Task執行時間比率所做的設定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PID USER PR NI VIRT RES SHR S <strong>%CPU</strong> %MEM TIME+ COMMAND</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1738 root 20 0 3880 264 212 R <strong>80.6</strong> 0.0 2:02.50 GroupA</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1739 root 20 0 3880 264 212 R <strong>19.9</strong> 0.0 0:41.98 GroupB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再以實際的執行結果來看,由於GroupA比GroupB多分到四倍的處理器執行時間,也因此在Console所顯示的結果上,GroupA大約每顯示四個字串結果後,GroupB才有機會顯示一次,如此也符合我們透過Control Group所設定分配的處理器執行資源比率.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:27</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:28</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:29</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:30</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupB:21</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:31</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:32</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:33</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:34</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupB:22</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:35</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:36</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:37</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:38</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupB:23</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:39</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:40</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:41</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:42</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupB:24</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:43</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:44</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>GroupA:45</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong>在Control Group之後,我們再針對原本Linux Kernel 2.6與在支援CFS排程機制後的核心排程,進一步的加以說明.<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CFS(Kernel 2.6.23)</strong><strong>之前</strong><strong>Linux Kernel 2.6 Time Slice</strong><strong>與</strong><strong>Real Time</strong><strong>優先級的簡要介紹</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示為CFS之前,Linux Kernel 2.6排程的優先級機制,右邊是屬於Task Real-Time優先權,左邊是Task的Nice Value,系統初始化後,一個最原始的行程產生時,預設的Real-Time優先權為0,而Nice優先權亦為0. Linux Kernel會根據Nice Value來計算該Task執行時間Time-Slice值的大小. 當使用者把行程的Nice Value遞減時(最低為-20),就表示該行程的優先權提高,相對的在排程時就會取得比較多的Time-Slice. 相對的,若不斷的增加Nice值(最大為19),就表示該行程的優先權降低,所取得的Time-Slice亦較低.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtfHop4S3EZphtbREaUlkzkX3elcLAiZIMT-T08nz-vXtHTOawffQDCSN8xf19UGqZhvhNuVzUulq79QWueQ_yuIwbMAgBC9XvrYM5aVtzoblfFbsrOPS2AYgypGD_lwdQQ4nHJJWhVWY/s1600/image008%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="621" data-original-width="707" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtfHop4S3EZphtbREaUlkzkX3elcLAiZIMT-T08nz-vXtHTOawffQDCSN8xf19UGqZhvhNuVzUulq79QWueQ_yuIwbMAgBC9XvrYM5aVtzoblfFbsrOPS2AYgypGD_lwdQQ4nHJJWhVWY/s1600/image008%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
但若使用者有Real-Time的需求時,希望特定的行程可以以較高的優先權執行,但又不希望如同增加Nice值一般,也對應增加了Time-Slice時,就必須要設定屬於Real-Time的優先權. 而real-Time的優先權最小為1,最大為99,該值越大在排程時會越先被執行到.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關Linux Kernel 2.6.10 核心Nice Value與對應之Time-Slice關係,可以參考下表</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">Nice Value</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="405">Time Slice</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402"><strong>-20<br />-19<br />-18<br />-17<br />-16<br />-15<br />-14<br />-13<br />-12<br />-11<br />-10<br />-9<br />-8<br />-7<br />-6<br />-5<br />-4<br />-3<br />-2<br />-1<br />0<br />1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="405">800ms (DEF_TIMESLICE * 4 * 40 /20)<br />780ms (DEF_TIMESLICE * 4 * 39 /20)<br />760ms (DEF_TIMESLICE * 4 * 38 /20)<br />740ms (DEF_TIMESLICE * 4 * 37 /20)<br />720ms (DEF_TIMESLICE * 4 * 36 /20)<br />700ms (DEF_TIMESLICE * 4 * 35 /20)<br />680ms (DEF_TIMESLICE * 4 * 34 /20)<br />660ms (DEF_TIMESLICE * 4 * 33 /20)<br />640ms (DEF_TIMESLICE * 4 * 32 /20)<br />620ms (DEF_TIMESLICE * 4 * 31 /20)<br />600ms (DEF_TIMESLICE * 4 * 30 /20)<br />580ms (DEF_TIMESLICE * 4 * 29 /20)<br />560ms (DEF_TIMESLICE * 4 * 28 /20)<br />540ms (DEF_TIMESLICE * 4 * 27 /20)<br />520ms (DEF_TIMESLICE * 4 * 26 /20)<br />500ms (DEF_TIMESLICE * 4 * 25 /20)<br />480ms (DEF_TIMESLICE * 4 * 24 /20)<br />460ms (DEF_TIMESLICE * 4 * 23 /20)<br />440ms (DEF_TIMESLICE * 4 * 22 /20)<br />420ms (DEF_TIMESLICE * 4 * 21 /20)<br />100ms (DEF_TIMESLICE * 1 * 20 /20)<br />95ms (DEF_TIMESLICE * 1 * 19 /20)<br />90ms (DEF_TIMESLICE * 1 * 18 /20)<br />85ms (DEF_TIMESLICE * 1 * 17 /20)<br />80ms (DEF_TIMESLICE * 1 * 16 /20)<br />75ms (DEF_TIMESLICE * 1 * 15 /20)<br />70ms (DEF_TIMESLICE * 1 * 14 /20)<br />65ms (DEF_TIMESLICE * 1 * 13 /20)<br />60ms (DEF_TIMESLICE * 1 * 12 /20)<br />55ms (DEF_TIMESLICE * 1 * 11 /20)<br />50ms (DEF_TIMESLICE * 1 * 10 /20)<br />45ms (DEF_TIMESLICE * 1 * 9 /20)<br />40ms (DEF_TIMESLICE * 1 * 8 /20)<br />35ms (DEF_TIMESLICE * 1 * 7 /20)<br />30ms (DEF_TIMESLICE * 1 * 6 /20)<br />25ms (DEF_TIMESLICE * 1 * 5 /20)<br />20ms (DEF_TIMESLICE * 1 * 4 /20)<br />15ms (DEF_TIMESLICE * 1 * 3 /20)<br />10ms (DEF_TIMESLICE * 1 * 2 /20)<br />5m (DEF_TIMESLICE * 1 * 1 /20)</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示,筆者把Nice值對應到的Task Priority與對應的排程機制進行對比,我們可以看到在Task Priority 100-139 (對應為Nice -20 – 19 或 User Priority 0-39)的區間內,為一般應用Task的排程機制,使用的Scheduling Class為Normal與Batch,而屬於Real-Time排程機制對應到的Task Priority為0-99,使用的Scheduling Class為Round-Robin與FIFO.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioDfBhguZaPulrBWQ9wKjeZuxu6wPruJ6E3tVY9ywAaeIQqZmQl6wN37XLJ-OwRfkXrIRRotgwR6HX1Mqtf-2zv5wIx8zV-LR9PvLffq96ROb4WjpblZd4lNLsvHScOnFBbZNyfI1O1Gg/s1600/image009%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="497" data-original-width="445" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioDfBhguZaPulrBWQ9wKjeZuxu6wPruJ6E3tVY9ywAaeIQqZmQl6wN37XLJ-OwRfkXrIRRotgwR6HX1Mqtf-2zv5wIx8zV-LR9PvLffq96ROb4WjpblZd4lNLsvHScOnFBbZNyfI1O1Gg/s1600/image009%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CFS</strong><strong>在</strong><strong>Linux Kernel 2.6.23</strong><strong>之後</strong><strong>,</strong><strong>參考</strong><strong>Tasks</strong><strong>優先級所施行的</strong><strong>Time Slice</strong><strong>與</strong><strong>Real-Time</strong><strong>措施</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於CFS RBTree的概念,由於會一直確保Virtual RunTime值的平衡,透過抓取佔據Virtual RunTime執行時間最短的Task來執行,因此像是原本排程中會透過Nice值計算對應Task可運作Time Slice的設計方式,就變的需要有所調整,也因此在CFS中會透過函式calc_delta_mine (實作在 kernel/sched.c),根據目前Task的優先級計算在排程時每次一個Scheduling Tick要增加的Delta值,也就是說如果該Task Nice值越高(優先級越低)該Delta值就越大,對該執行的Task來說就是Virtual RunTime在運作時,增加的速度越快(等於縮短實際執行的時間),反之,如果該Task Nice值越低(優先級越高)則Delta值就越小,在每次Scheduling Tick觸發時,Virtual RunTime增加的速度越慢,能獲得處理器執行的實際時間也就越長.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考kernel/sched_fair.c的實作,函式calc_delta_mine的呼叫來源有兩處,</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">來源</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">1,從函式calc_delta_fair中呼叫<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>static inline unsigned long</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>calc_delta_fair(unsigned long delta, struct sched_entity *se)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>{</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>if (unlikely(se->load.weight != NICE_0_LOAD))</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>delta = </strong><strong>calc_delta_mine</strong><strong>(delta, NICE_0_LOAD, &se->load);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>return delta;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">當目前的Scheduling Entity Load Weight不為NICE 0 的Load Weight (=1024)時,就會根據所帶入的Delta值與對應的Load Weight,計算出新的Delta值,通常用在<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,更新目前運作的Current Task執行的Virtual RunTime時,就會呼叫calc_delta_fair用以取得Delta時間,並累加至變數curr->sum_exec_runtime中. (有關的實作可以參考函式__update_curr).</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,用在判斷是否要中斷目前的Task讓下一個Task (Scheduling Entity)可以進來執行,實作部分可以參考函式 wakeup_preempt_entity,首先會判斷是否要取代的Task Virtual RunTime比目前的Task大,若是就直接返回-1,再來就以 1ms (=sysctl_sched_wakeup_granularity)計算要取代Task的WakeUp Granularity,若兩個Task的Virtual RunTime差值大於WakeUp Granularity就返回1,表示可以用下一個Task取代目前的Task,反之則返回0.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,用在取得要置入Run Queue的Task Scheduling Entity的Virtual RunTime Slice值,實作的部分可以參考函式place_entity與函式 sched_vslice.</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">2,從函式sched_slice中呼叫<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>{</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>for_each_sched_entity(se) {</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>struct load_weight *load;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>struct load_weight lw;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>cfs_rq = cfs_rq_of(se);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>load = &cfs_rq->load;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>if (unlikely(!se->on_rq)) {</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>lw = cfs_rq->load;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>update_load_add(&lw, se->load.weight);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>load = &lw;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>slice =</strong><strong> calc_delta_mine</strong><strong>(slice, se->load.weight, load);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>return slice;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>}</strong></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="403">用來取得Task Scheduling Entity的Wall-Time slice.</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以筆者在 64bits處理器下,所使用的Linux Kernel 2.6.38.6來說,函式calc_delta_mine的幾個關鍵數字如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,NICE_0_LOAD 為1024 (參考kernel/sched.c原始碼 NICE_0_LOAD=SCHED_LOAD_SCALE,並參考include/linux/sched.h中 SCHED_LOAD_SCALE = (1L << SCHED_LOAD_SHIFT), 而SCHED_LOAD_SHIFT = 10)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,LONG_MAX為9223372036854775807 (ㄟ…我是用64bits處理器驗證,所以該值為0x7FFFFFFFFFFFFFFF) (參考原始碼include/linux/kernel.h,其中LONG_MAX = ((long)(~0UL>>1)) )</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,SRR(x, y) 為 (((x) + (1UL << ((y) – 1))) >> (y)) (參考原始碼kernel/sched.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,BITS_PER_LONG:64</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,WMULT_CONST:4294967296 (=0x100000000)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,WMULT_SHIFT:32</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式calc_delta_mine宣告原型如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static unsigned long calc_delta_mine(unsigned long delta_exec, unsigned long weight, struct load_weight *lw)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據目前的實作,Delta的返回值會透過如下流程來計算</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,如果lw->inv_weight 為0,就會執行下列的計算</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lw->inv_weight = 1 + (WMULT_CONST-lw->weight/2) / (lw->weight+1);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,Temp-Delta值為delta_exec * weight</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-1,如果Temp-Delta > 0x100000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-1-1,Delta = SRR(SRR(Temp-Delta, WMULT_SHIFT/2) * lw->inv_weight,WMULT_SHIFT/2);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2,如果Temp-Delta <= 0x100000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1,Delta = SRR(Temp-Delta * lw->inv_weight, WMULT_SHIFT);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉實際的例子來說,當傳入的參數</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,delta_exec=6000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,weight=1024</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,lw->weight=1024</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,lw->inv_weight=0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於 lw->inv_weight為0,因此會進行如下的計算</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lw->inv_weight=1 + ( 0x100000000 – 1024/2) / (1024+1) = 4190212.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而Temp-Delta 的值 = delta_exec * weight = 6000000 * 1024 = 6144000000=0x16E360000,大於 WMULT_CONST的值 (0x100000000).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因此,最後的Delta執會進行如下計算</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Delta = SRR(SRR(Temp-Delta, WMULT_SHIFT/2) * lw->inv_weight,WMULT_SHIFT/2)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=SRR(SRR(0x16E360000, 32/2) * 4190212,32/2)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=SRR(((0x16E360000 + 1<<15)>>16)* 4190212,16)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=SRR( ( 0x16E368000 >>16)* 4190212,16)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=SRR( 0x16E36* 4190212,16)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=SRR( 392832375000,16)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
= (392832375000 + 1<15) >> 16</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=<strong>5994146</strong>.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對應到不同函式參數所換算回來的Delta值,筆者整理如下表所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">delta_exec</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">weight</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">lw->weight</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">呼叫前的 lw->inv_weight</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">呼叫後的 lw->inv_weight</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">返回Delta值<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
units: nanoseconds</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">40</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">26</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">502</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">206</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">650</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">420</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">3850</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">2486</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">4100</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">2647</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">4351</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">2809</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">4599</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">2969</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6585</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">2696</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">10315</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">6660</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">11893</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">4869</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">11972</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">4902</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">22495</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">9210</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">27733</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">11355</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">53413</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">34486</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">54762</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">35357</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">55454</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">35804</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">60593</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">39122</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">118071</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">76232</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">127372</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">82238</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">724313</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">467652</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">773872</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">316851</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">782207</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">320264</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">1000000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">645649</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">1000000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1717300</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">409436</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">1000000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2501</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">645649</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">1187365</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">766622</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">2984950</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2708050</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">1927231</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">4190212</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">5994146</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2048</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2096129</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">2998537</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">2063</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">2080895</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">2080895</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">2976744</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">3072</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1397646</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">1999349</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">4096</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">1048320</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">1048320</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">1499634</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">6706</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">640371</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">916058</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">9978</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">430401</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">615694</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">5673</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">756956</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">1677128</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">6000000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">6244</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">687745</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">687745</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">1523783</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">20250000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">2501</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">63658</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">67468</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">795567</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">21750000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">44870</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">95718</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">768770</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100">21750000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101">1586</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113">45432</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179">0</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171">94534</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142">759261</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="100"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="101"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="113"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="179"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="171"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="142"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過上述的計算,我們可以知道影響Virtual RunTime Slice增加的Delta值最大的關鍵是在下面三個參數,筆者在此也簡述這三個參數的意義.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,delta_exec: 是目前Virtual RunTime Slice的Delta值,會用來當作calc_delta_mine的第一個參數,用以計算出新的Delta值. 根據目前的實作,這個值可以表示在呼叫函式calc_delta_mine前,該Task所執行的時間間隔,也就是說如果該值越大,表示該Task在這次呼叫函式calc_delta_mine前,所得到的執行時間越長,相對的再透過Weight的計算後,下一次得到的Delta值就越大,對應到真實執行時間就會越少 (因為Delta值變大,執行時Virtual RunTime增加的速度就越快.).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,weight:為目前Task的Load Weight,若Task的Nice值為 0,則此值為1024. 這個值越大,透過calc_delta_mine所計算的inv_weight 值越小,對應該 Task所計算出來的Delta值也越小,也就表示該Task的Virtual RunTime增加的越慢,因此實際得到處理器執行的真實時間就越長.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,lw->weight:為目前排程單位sched_entity的Load Weight . 如果se->load.weight等於Nice 0的 Load Weight (1024),函式calc_delta_fair就會直接返回所傳入的Delta值,反之才會進入函式calc_delta_mine,重新計算新的Delta值. RunQueue的參數load->weight,會等於該RunQueue中所有Schedule Entity的load->weight總合,分別表示整個RunQueue執行單元的負荷與個別執行單元的負荷.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考函式set_load_weight的實作(in kernel/sched.c),我們可以把不同的Task Priority ,Nice值與所對應的Scheduling Entity Load Weight值對應如下表所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">Task Priority</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">Task Nice</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">Scheduling Entity Load Weight</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">Scheduling Entity Load Inverse-Weight</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">100</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-20</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">88761</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">48388</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">101</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-19</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">71755</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">59856</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">102</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-18</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">56483</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">76040</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">103</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-17</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">46273</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">92818</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">104</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-16</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">36291</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">118348</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">105</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-15</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">29154</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">147320</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">106</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-14</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">23254</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">184698</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">107</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-13</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">18705</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">229616</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">108</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-12</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">14949</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">287308</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">109</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-11</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">11916</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">360437</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">110</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-10</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">9548</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">449829</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">111</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-9</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">7620</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">563644</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">112</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-8</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">6100</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">704093</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">113</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-7</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">4904</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">875809</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">114</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-6</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">3906</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">1099582</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">115</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-5</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">3121</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">1376151</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">116</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-4</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">2501</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">1717300</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">117</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-3</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">1991</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">2157191</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">118</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-2</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">1586</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">2708050</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">119</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">-1</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">1277</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">3363326</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">120</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">0</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">1024</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">4194304</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">121</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">1</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">820</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">5237765</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">122</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">2</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">655</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">6557202</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">123</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">3</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">526</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">8165337</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">124</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">4</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">423</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">10153587</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">125</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">5</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">335</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">12820798</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">126</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">6</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">272</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">15790321</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">127</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">7</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">215</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">19976592</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">128</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">8</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">172</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">24970740</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">129</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">9</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">137</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">31350126</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">130</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">10</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">110</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">39045157</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">131</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">11</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">87</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">49367440</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">132</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">12</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">70</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">61356676</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">133</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">13</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">56</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">76695844</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">134</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">14</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">45</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">95443717</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">135</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">15</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">36</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">119304647</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">136</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">16</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">29</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">148102320</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">137</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">17</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">23</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">186737708</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">138</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">18</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">18</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">238609294</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">139</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127">19</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234">15</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">286331153</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="127"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="234"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般來說,如果Nice值加一 (也就是優先級降低一),大約會減少10%處理器的執行時間,而如果是Nice值減一(也就是優先級調升),大約就會增加10%處理器的執行時間.而參考上表整理的結果,每個Nice值的區間所對應的Weight大約會相差1.25倍. 例如15*1.25=18.75,18*1.25=22.5…</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
介紹到此,我們可以發現像是O(N),O(1)或是CFS (O(Log2(N))),都沒有把處理器不等速的問題考慮進來.也因此,在支援像是aSMP架構時,這部份的排程機制改善,就是攸關能否發揮aSMP架構優勢的關鍵.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
多核心架構肯定會是未來智慧型手機晶片的主流,要能在智慧型手機方案中發揮架構的優勢,了解Linux Kernel的排程機制,會是一個必要的基礎功課.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文主要著重在Linux Kernel排程的介紹,從前一代的Linux核心排程機制談起,到目前基於CFS的核心排程與相關資料結構的說明. 但要發揮多核心的優勢,除了Linux Kernel的層次外,在Android Framework上也需有所因應,後續筆者會再進一步的加以介紹.希望能讓閱讀本文的開發者有所助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-90729614454259975962017-06-03T17:19:00.002-07:002017-06-03T17:19:33.354-07:00談Linux Kernel巨集 do{…}while(0) 的撰寫方式<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
談Linux Kernel巨集 do{…}while(0) 的撰寫方式</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
談Linux Kernel巨集 do{…}while(0) 的撰寫方式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
by loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
hlchou@mail2000.com.tw</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
不同於過去文章,都是以技術的探索為主,這次的文章,無關乎技術深度,但希望凸顯出Linux Kernel實作上的巧思.筆者相信對大家會有所收穫,也因此選擇以此為主題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在程式設計寫作時,巨集Marco是常見的寫法,相信閱讀本文的開發者,也非常熟悉才是.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也因為是基礎知識,大家都認為對巨集的使用都已經了然於心,但其實簡單的事物背後也是有它的思考.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Trace Linux Kernel原始碼時,常會看到把巨集用 do {….} while(0)的寫法包裝起來,時間久了,也認為這是一個合理的作法,但原因呢?就真的沒有仔細的去思考過,從編譯器的角度來說,用了do{…..} while(0)的寫法,在不開啟編譯優化參數的前提下,由於多了新的判斷,應該是會比起單純的 {….}產生額外的程式碼,影響到執行效能才是(例如,多了CMP或Branch條件判斷).而且主觀上,以Linux Kernel這樣等級的Open Source計畫,應該是不會設計出一個明知會導致效能降低的寫法才是.但沒有實際去驗證過,總是存在心頭上的一個問號.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
既然有了這樣的發想,也就有了本文的誕生,在這篇文章中將會透過實際的例子,比對編譯後的程式碼,來確認Linux Kernel如此撰寫的影響.更進一步的來說,會參考Linux Kernel Coding Style與Writing CPP Marcos文章中的案例,藉此說明巨集使用上考量. 希望能對閱讀本文的讀者,帶來收穫.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Linux Kernel </strong><strong>中的例子</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,我們以 Linux Kernel中使用到do {….} while(0)的Source Code作說明,藉此了解目前實作的例子.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(1) 在檔案include/linux/spinlock.h 中,有如下宣告</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# define raw_spin_lock_init(lock) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
do { \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static struct lock_class_key __key; \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
\</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__raw_spin_lock_init((lock), #lock, &__key); \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} while (0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在kernel/fork.c中,呼叫 raw_spin_lock_init的方式為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static void rt_mutex_init_task(struct task_struct *p)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
raw_spin_lock_init(&p->pi_lock);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef CONFIG_RT_MUTEXES</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
plist_head_init_raw(&p->pi_waiters, &p->pi_lock);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
p->pi_blocked_on = NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(2) 在檔案include/linux/cred.h 中,有如下宣告</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define put_group_info(group_info) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
do { \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (atomic_dec_and_test(&(group_info)->usage)) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
groups_free(group_info); \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} while (0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在kernel/cred.c中,呼叫 put_group_info 的方式為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (cred->group_info)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
put_group_info(cred->group_info);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來,讓我們用實際的案例來驗證do {….} while(0)與{…..}的寫法,並比對透過編譯器產生的結果與Linux Kernel Coding Style文件,了解Linux Kernel對巨集的設計建議</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>對編譯器而言</strong><strong>,DoWhile0</strong><strong>會得到比較好的編譯結果嗎</strong><strong>?</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在本段驗證前,其實,腦中有個念頭,就是是否GCC對這種DoWhile0寫法有比較好的編譯結果,能讓運作效率更佳,所以Linux Kernel才會選擇這樣的設計方式.也因此我們透過如下的代碼來進行驗證,並且會透過Open Source的ARM GCC 4.4與商用版本的ARM RVCT 4.0 分別帶入優化參數 0,1,2 比對產生的編譯結果.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="523">int funcA(int IN_A,int IN_B)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int OUT=0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(IN_A)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OUT=(IN_A+3)*IN_B;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OUT=(IN_A+33)*IN_B;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return OUT;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int funcB(int IN_A,int IN_B)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int OUT=0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(IN_A)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
do{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OUT=(IN_A+3)*IN_B;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}while(0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
do{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OUT=(IN_A+33)*IN_B;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}while(0);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return OUT;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vRet;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vRet=funcA(0,3);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“0 A:%ld\n”,vRet);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vRet=funcB(0,3);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“0 B:%ld\n”,vRet);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vRet=funcA(2,3);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“2 A:%ld\n”,vRet);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vRet=funcB(2,3);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“2 B:%ld\n”,vRet);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過 ARM GCC 以-O0編譯後,執行結果如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# ./main</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0 A:99</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0 B:99</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2 A:15</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2 B:15</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
使用arm-eabi-objdump -x -D 進行反組譯</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
比對 funcA與funcB的結果如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">funcA</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="405">funcB</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">0: e52db004 push {fp} ; (str fp, [sp, #-4]!)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4: e28db000 add fp, sp, #0 ; 0x0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8: e24dd014 sub sp, sp, #20 ; 0x14</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
c: e50b0010 str r0, [fp, #-16]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10: e50b1014 str r1, [fp, #-20]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
14: e3a03000 mov r3, #0 ; 0x0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18: e50b3008 str r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1c: e51b3010 ldr r3, [fp, #-16]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
20: e3530000 cmp r3, #0 ; 0x0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
24: 0a000005 beq 40 <funcA+0x40></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
28: e51b3010 ldr r3, [fp, #-16]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2c: e2833003 add r3, r3, #3 ; 0x3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
30: e51b2014 ldr r2, [fp, #-20]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
34: e0030392 mul r3, r2, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
38: e50b3008 str r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3c: ea000004 b 54 <funcA+0x54></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40: e51b3010 ldr r3, [fp, #-16]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
44: e2833021 add r3, r3, #33 ; 0x21</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
48: e51b2014 ldr r2, [fp, #-20]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4c: e0030392 mul r3, r2, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
50: e50b3008 str r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
54: e51b3008 ldr r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
58: e1a00003 mov r0, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5c: e28bd000 add sp, fp, #0 ; 0x0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
60: e8bd0800 pop {fp}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
64: e12fff1e bx lr</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="405">68: e52db004 push {fp} ; (str fp, [sp, #-4]!)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6c: e28db000 add fp, sp, #0 ; 0x0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
70: e24dd014 sub sp, sp, #20 ; 0x14</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
74: e50b0010 str r0, [fp, #-16]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
78: e50b1014 str r1, [fp, #-20]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7c: e3a03000 mov r3, #0 ; 0x0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
80: e50b3008 str r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
84: e51b3010 ldr r3, [fp, #-16]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
88: e3530000 cmp r3, #0 ; 0x0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8c: 0a000005 beq a8 <funcB+0x40></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
90: e51b3010 ldr r3, [fp, #-16]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
94: e2833003 add r3, r3, #3 ; 0x3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
98: e51b2014 ldr r2, [fp, #-20]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9c: e0030392 mul r3, r2, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
a0: e50b3008 str r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
a4: ea000004 b bc <funcB+0x54></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
a8: e51b3010 ldr r3, [fp, #-16]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ac: e2833021 add r3, r3, #33 ; 0x21</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b0: e51b2014 ldr r2, [fp, #-20]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b4: e0030392 mul r3, r2, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b8: e50b3008 str r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bc: e51b3008 ldr r3, [fp, #-8]</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
c0: e1a00003 mov r0, r3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
c4: e28bd000 add sp, fp, #0 ; 0x0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
c8: e8bd0800 pop {fp}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cc: e12fff1e bx lr</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以發現產生的指令集是一致的,再進一步用arm-eabi-gcc 搭配 -O1,O2的優化來編譯,也可以發現,優化的結果與產生的指令集,兩者都是一致的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在GCC編譯器後,我們改用ARM RVCT 4.0編譯器對上述程式碼進行編譯動作,經過比對,只有在armcc 用-O0時,兩者有如下的差異</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">funcA</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="405">funcB</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="402">0x00000000: e1a02000 . .. MOV r2,r0<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000004: e3a00000 …. MOV r0,#0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000008: e3520000 ..R. CMP r2,#0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000000c: 0a000002 …. BEQ {pc}+0x10 ; 0x1c</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000010: e2823003 .0.. ADD r3,r2,#3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000014: e0000193 …. MUL r0,r3,r1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000018: ea000001 …. B {pc}+0xc ; 0x24</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000001c: e2823021 !0.. ADD r3,r2,#0x21</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000020: e0000193 …. MUL r0,r3,r1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000024: e12fff1e ../. BX lr</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="405">0x00000028: e1a02000 . .. MOV r2,r0<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000002c: e3a00000 …. MOV r0,#0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000030: e3520000 ..R. CMP r2,#0</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000034: 0a000003 …. BEQ {pc}+0x14 ; 0x48</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>0x00000038: e1a00000 …. MOV r0,r0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000003c: e2823003 .0.. ADD r3,r2,#3</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000040: e0000193 …. MUL r0,r3,r1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000044: ea000003 …. B {pc}+0x14 ; 0x58</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>0x00000048: e1a00000 …. MOV r0,r0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000004c: e2823021 !0.. ADD r3,r2,#0x21</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000050: e0000193 …. MUL r0,r3,r1</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>0x00000054: e1a00000 …. MOV r0,r0</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000058: e12fff1e ../. BX lr</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
多了三處可以忽略的 “mov r0,r0“ 動作,但其它的編譯結果都是一致的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
總結來說,除了ARM RVCT 4.0的-O0優化參數外,使用ARM GCC或是ARM RVCT 4.0的編譯環境,對 do {….} while(0)與{…..}的寫法,只要使用到-O1或之後的優化參數,最終產生的編譯結果機械碼兩者是一致的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
所以,筆者原先的揣測看來是多想了…@_@.再來讓我們進一步從程式碼撰寫的角度來分析.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>對</strong><strong> </strong><strong>if/else </strong><strong>區塊的影響</strong><strong></strong></div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="462">#define Test_DoWhileZero(IN_A,IN_B) \<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
do { \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(IN_A) \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{ OUT=(IN_A+3)*IN_B;} \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{ OUT=(IN_A+33)*IN_B;} \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} while (0)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define Test_Normal(IN_A,IN_B) \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{ \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(IN_A) \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{ OUT=(IN_A+3)*IN_B;} \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{ OUT=(IN_A+33)*IN_B;} \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int funcA(int IN_A,int IN_B)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int OUT=0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(IN_B)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Test_DoWhileZero(IN_A,IN_B);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Error IB_B==NULL\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return OUT;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int funcB(int IN_A,int IN_B)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int OUT=0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(IN_B)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Test_Normal(IN_A,IN_B);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Error IB_B==NULL\n”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return OUT;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vRet;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vRet=funcA(0,3);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“0 A:%ld\n”,vRet);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vRet=funcB(0,3);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“0 B:%ld\n”,vRet);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vRet=funcA(2,3);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“2 A:%ld\n”,vRet);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vRet=funcB(2,3);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“2 B:%ld\n”,vRet);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過arm-eabi-gcc編譯時,會導致如下的錯誤發生</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
In function ‘funcB':</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
error: ‘else’ without a previous ‘if’</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
原因在於巨集的宣告,如果是 {…….},在使用巨集Test_Normal時又有加上 ; 結尾,就會導致原本的 if/else區塊變成如下情況</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(..)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
….</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
導致 if 條件式在else前就已經結尾.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
反之,使用do{…}while(0)寫法的巨集,對應到上述用法時,if/else區塊的展開為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(..)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
do{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}while(0);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並不會影響到原本 if/else區塊的條件判斷正確性,又可以滿足巨集中需要多行程式碼時,的程式碼撰寫需求.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
總結來說,採用DoWhile0的寫法,可以滿足之後要用inline函式取代巨集的需求,而用在if/else這種條件判斷時,巨集展該後的程式碼也能無誤運作.最最最重要的是,從實際編譯器產生的機械碼來說,並不會因為如此撰寫,導致系統運作效率的降低.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Linux Kernel Coding Style</strong><strong>文件</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以參考Linux Kernel文件”Linux kernel coding style” (檔案路徑Documentation/CodingStyle),了解Linux Kernel對於巨集使用的說明. 這份文件共有18章,是Linux Kernel程式開發者值得參考的程式設計說明,跟本文有關的DoWhile0巨集寫法是在第12章 “Macros, Enums and RTL”,筆者大致說明如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,要避免巨集影響到執行流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,在巨集中的DoWhile0,存在return返回值,這會影響到使用這巨集模組的執行流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define FOO(x) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
do { \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (blah(x) < 0) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return -EBUGGERED; \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} while(0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,避免在巨集宣告中,參考到特定的變數名稱</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,使用FOO巨集時,參考到區域變數index</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define FOO(val) bar(index, val)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在使用巨集FOO的函式中,如果沒有宣告區域變數index,就會導致如下錯誤 “error: ‘index’ undeclared (first use in this function)”.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而若是把index宣告為全域變數,然後使用上述的FOO巨集時,就會在編譯時產生如下的錯誤 “warning: built-in function ‘index’ declared as non-function”,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在巨集的宣告時,儘量要避免額外參考到非巨集帶入的變數,可避免在後續使用上,所造成的問題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,巨集所帶的參數不應該當做L-Value.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,把巨集FOO帶參數直接定義為另一個目標值.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define FOO(val) val</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int func()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int x=10;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FOO(x)+=30;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return x;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這樣的巨集可以正常運作,但一旦把巨集改為inline函式時</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
inline int FOO(int val)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return val;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就會導致如下的錯誤 “error: invalid lvalue in assignment”,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4, 巨集定義的運算式與常數必須有括號前後封裝.以避免因為遺忘了運算優先順序的問題,所導致的錯誤.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下例子所示,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define CONSTANTA 2&7</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define CONSTEXPA (400+CONSTANTA)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define CONSTANTB (2&7)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define CONSTEXPB (400+CONSTANTB)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在巨集展開後,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CONSTEXPA =(400+2&7)=402&7=2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CONSTEXPB=(400+(2&7))=400+2=402</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
避免透過巨集封裝運算式時,因為括號沒有明確的配置,導致原本設計上,規劃之外的錯誤發生.更多這部份的例子,可以參考下一段的案例.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>更進一步</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以參考 ”Writing C/C++ Macros”文件(路徑 <a href="http://www.ebyte.it/library/codesnippets/WritingCppMacros.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.ebyte.it/library/codesnippets/WritingCppMacros.html</a>)中,有關巨集解釋的九個章節,對於理解巨集有很大的幫助,在實際的驗證上可以透過GCC -E的參數,驗證C程式碼在巨集展開後的結果.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若你覺得對巨集已經很清楚,不彷試試回答下面三個值的結果.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
定義巨集為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define SquareOf(x) x*x</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
變數 int vBase=7;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而以下這三個巨集執行結果,應該是多少呢?</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SquareOf(vBase) , SquareOf(vBase+1) 與 SquareOf(vBase+vBase).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過程式碼驗證</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define SquareOf(x) x*x</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vBase=7;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“vBase=%d and define SquareOf(x) = x*x \n”,vBase);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“SquareOf(vBase)=%d \n”,SquareOf(vBase));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“SquareOf(vBase+1)=%d \n”,SquareOf(vBase+1));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“SquareOf(vBase+vBase)=%d \n”,SquareOf(vBase+vBase));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
搭配gcc -E,可以看到巨集展開後的內容如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vBase=7;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“vBase=%d and define SquareOf(x) = x*x \n”,vBase);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“SquareOf(vBase)=%d \n”,<strong>vBase*vBase</strong>);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“SquareOf(vBase+1)=%d \n”,<strong>vBase+1*vBase+1</strong>);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“SquareOf(vBase+vBase)=%d \n”,<strong>vBase+vBase*vBase+vBase</strong>);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SquareOf(vBase)為49,而SquareOf(vBase+1)= vBase+1*vBase+1=7+7+1=15. (不是8*8=64),SquareOf(vBase+vBase)= vBase+vBase*vBase+vBase=7+49+7=63. (不是14*14=196).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
另一個可能犯錯的例子是,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
定義巨集為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define SumOf(x,y) (x)+(y)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
變數 int vBase1=3, vBase2=5;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以下這兩個巨集執行結果,應該是多少呢?</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SumOf(vBase1,vBase2) 與 2*SumOf(vBase1,vBase2).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過程式碼驗證<br />#define SumOf(x,y) (x)+(y)<br />int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vBase1=3, vBase2=5;<br />printf(“vBase1=%d,vBase2=%d and define SumOf(x,y)=(x)+(y) \n”,vBase1,vBase2);<br />printf(“SumOf(vBase1,vBase2)=%d \n”,SumOf(vBase1,vBase2));<br />printf(“2*SumOf(vBase1,vBase2)=%d \n”,2*SumOf(vBase1,vBase2));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;<br />}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
搭配gcc -E,可以看到巨集展開後的內容如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int vBase1=3, vBase2=5;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“vBase1=%d,vBase2=%d and define SumOf(x,y)=(x)+(y) \n”,vBase1,vBase2);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“SumOf(vBase1,vBase2)=%d \n”,(vBase1)+(vBase2));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“2*SumOf(vBase1,vBase2)=%d \n”,2*(vBase1)+(vBase2));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SumOf(vBase1,vBase2)為8,而2*SumOf(vBase1,vBase2)= 2*(vBase1)+(vBase2)=6+5=11. (不是2*8=16).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要讓結果符合預期,SquareOf與 SumOf巨集需修改為如下內容.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define SquareOf(x) ((x)*(x))<br />#define SumOf(x,y) ((x)+(y))</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文從DoWhile0的驗證,到參考有關巨集介紹的文件作探討,我們可以知道像是Linux Kernel這樣受矚目的Open Source計畫,在相關的實作上,也確實有它的思考縝密度.在閱讀Linux Kernel Source Code時,包括在判斷if/else優化動作的likely/unlikely巨集,會透過GCC內建函式__builtin_expect在程式碼編譯時進行條件判斷的優化. 或更進一步藉由GCC內建函式__builtin_constant_p判斷常數,讓__branch_check__巨集可以進行Profiling的動作.而有關平台的部份,像是Memory Barrier的操作,也透過巨集封裝,讓開發者可以便利的使用,這些設計上的思維,都必須要有對編譯器或是平台深度的理解,才能夠達成的.</div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-55684895703660960112017-06-03T17:18:00.000-07:002017-06-03T17:18:02.729-07:00Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(4) Linux 多核心啟動流程-kthreadd 與相關的核心模組<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(4) Linux 多核心啟動流程-kthreadd 與相關的核心模組</h1>
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Android </span>筆記<span style="font-family: "Times New Roman", serif;">-Linux Kernel SMP (Symmetric Multi-Processors) </span>開機流程解析 <span style="font-family: "Times New Roman", serif;">Part(4) Linux </span>多核心啟動流程<span style="font-family: "Times New Roman", serif;">–</span><span style="font-family: "Times New Roman", serif;">kthreadd 與相關的核心模組</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "Times New Roman", serif;">by loda</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "Times New Roman", serif;">hlchou@mail2000.com.tw</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">kthread</span>第一次出現在<span style="font-family: "Times New Roman", serif;">Linux Kernel </span>中是在<span style="font-family: "Times New Roman", serif;">Kernel</span>版本<span style="font-family: "Times New Roman", serif;">2.6.4</span>時<span style="font-family: "Times New Roman", serif;">,</span>一開始的實作尚未有本文提到的<span style="font-family: "Times New Roman", serif;">kthreadd Task</span>的具體架構<span style="font-family: "Times New Roman", serif;">,</span>隨著版本的演進<span style="font-family: "Times New Roman", serif;">,</span>除了這部份的設計完整外<span style="font-family: "Times New Roman", serif;">,</span>需要產生<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的實作也都已經改用<span style="font-family: "Times New Roman", serif;">kthread</span>機制<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文會先針對<span style="font-family: "Times New Roman", serif;">kthreadd Task</span>行為加以說明<span style="font-family: "Times New Roman", serif;">,</span>並會以在啟動後<span style="font-family: "Times New Roman", serif;">,</span>屬於<span style="font-family: "Times New Roman", serif;">Kernel Mode</span>產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的個別行為與功能做一個介紹<span style="font-family: "Times New Roman", serif;">,</span>由於這部份涉及的範圍不少<span style="font-family: "Times New Roman", serif;">,</span>筆者會以自己的角度選擇認為值得加以說明的項目<span style="font-family: "Times New Roman", serif;">,</span>相信應該足以涵蓋大多數人對於<span style="font-family: "Times New Roman", serif;">Linux Kernel Mode Tasks</span>所需的範圍<span style="font-family: "Times New Roman", serif;">.</span>如果有所不足之處<span style="font-family: "Times New Roman", serif;">,</span>也請透過<span style="font-family: "Times New Roman", serif;">Linux Kernel Hacking</span>加以探索<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡要來說<span style="font-family: "Times New Roman", serif;">,</span>位於<span style="font-family: "Times New Roman", serif;">Kernel Mode</span>的<span style="font-family: "Times New Roman", serif;">Tasks</span>產生<span style="font-family: "Times New Roman", serif;">,</span>除了直接透過<span style="font-family: "Times New Roman", serif;">kernel_thread</span>函式外<span style="font-family: "Times New Roman", serif;">,</span>還可以有兩個來源<span style="font-family: "Times New Roman", serif;">,</span>一個是透過<span style="font-family: "Times New Roman", serif;">kthread_create (</span>實作上<span style="font-family: "Times New Roman", serif;">,</span>也是透過函式 <span style="font-family: "Times New Roman", serif;">Kernel_Thread)</span>產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>另一個則是透過<span style="font-family: "Times New Roman", serif;">WorkQueue</span>機制產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>前者可以依據設計者自己對系統架構的掌握<span style="font-family: "Times New Roman", serif;">,</span>去設計多工機制<span style="font-family: "Times New Roman", serif;">(</span>例如<span style="font-family: "Times New Roman", serif;">,</span>使用稍後提到的<span style="font-family: "Times New Roman", serif;">Linked List Queue).</span>而後者<span style="font-family: "Times New Roman", serif;">,</span>則是由<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>提供延遲處理工作的機制<span style="font-family: "Times New Roman", serif;">,</span>讓每個核心的<span style="font-family: "Times New Roman", serif;">Tasks</span>可以透過<span style="font-family: "Times New Roman", serif;">WorkQueue</span>機制把要延遲處理<span style="font-family: "Times New Roman", serif;">/</span>指定處理器<span style="font-family: "Times New Roman", serif;">/</span>指定延遲時間的工作<span style="font-family: "Times New Roman", serif;">,</span>交派給<span style="font-family: "Times New Roman", serif;">WorkQueue.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在實際的應用上<span style="font-family: "Times New Roman", serif;">,WorkQueue</span>還可以用以實現中斷的<span style="font-family: "Times New Roman", serif;">BottomHalf</span>機制<span style="font-family: "Times New Roman", serif;">,</span>讓中斷觸發時對<span style="font-family: "Times New Roman", serif;">Timing</span>要求高的部分<span style="font-family: "Times New Roman", serif;">(TopHalf)</span>可以在<span style="font-family: "Times New Roman", serif;">Interrupt Handler</span>中盡快執行完畢<span style="font-family: "Times New Roman", serif;">,</span>透過<span style="font-family: "Times New Roman", serif;">WorkQueue</span>把需要較長時間執行的部分<span style="font-family: "Times New Roman", serif;">(BottomHalf)</span>交由<span style="font-family: "Times New Roman", serif;">WorkQueue</span>延遲執行實現<span style="font-family: "Times New Roman", serif;">. (</span>等同於<span style="font-family: "Times New Roman", serif;">RTOS</span>下的<span style="font-family: "Times New Roman", serif;">LISR/HISR).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Linux Kernel</strong></span></span><span style="font-size: small;"><strong>的基礎</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Tasks.</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>中有三個最基礎的<span style="font-family: "Times New Roman", serif;">Tasks,</span>分別為<span style="font-family: "Times New Roman", serif;">PID=0</span>的<span style="font-family: "Times New Roman", serif;">Idle Task,PID=1</span>負責初始化所有使用者環境與行程的 <span style="font-family: "Times New Roman", serif;">init Task,</span>與<span style="font-family: "Times New Roman", serif;">PID=2</span>負責產生<span style="font-family: "Times New Roman", serif;">Kernel Mode</span>行程的 <span style="font-family: "Times New Roman", serif;">kthreadd Task.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中<span style="font-family: "Times New Roman", serif;">,Idle Task</span>主要用來在系統沒有其他工作執行時<span style="font-family: "Times New Roman", serif;">,</span>可以執行省電機制<span style="font-family: "Times New Roman", serif;">(PM Idle)</span>或透過 <span style="font-family: "Times New Roman", serif;">Idle Migration</span>把多核心其它處理器上的工作進行重分配<span style="font-family: "Times New Roman", serif;">(Load Balance),</span>讓處於<span style="font-family: "Times New Roman", serif;">Idle</span>的處理器可以分擔<span style="font-family: "Times New Roman", serif;">Task</span>工作<span style="font-family: "Times New Roman", serif;">,</span>充分利用系統運算資源<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而<span style="font-family: "Times New Roman", serif;">init Task</span>是所有<span style="font-family: "Times New Roman", serif;">User Mode Tasks</span>的父行程<span style="font-family: "Times New Roman", serif;">,</span>包含啟動時的<span style="font-family: "Times New Roman", serif;">Shell Script</span>執行<span style="font-family: "Times New Roman", serif;">,</span>或是載入必要的應用程式<span style="font-family: "Times New Roman", serif;">,</span>都會基於<span style="font-family: "Times New Roman", serif;">init Task</span>的執行來實現<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來就是本文主要談的<span style="font-family: "Times New Roman", serif;">kthreadd Task,</span>這是在<span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6</span>所引入的機制<span style="font-family: "Times New Roman", serif;">,</span>在這之前要產生<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>需直接使用函式<span style="font-family: "Times New Roman", serif;">kernel_thread,</span>而所產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>父行程會是當下產生<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的行程<span style="font-family: "Times New Roman", serif;">(</span>或該父行程結束後<span style="font-family: "Times New Roman", serif;">,</span>改為<span style="font-family: "Times New Roman", serif;">init Task(PID=1)). </span>在<span style="font-family: "Times New Roman", serif;">kthreadd</span>的機制下<span style="font-family: "Times New Roman", serif;">,User Mode</span>與<span style="font-family: "Times New Roman", serif;">Kernel Mode Task</span>的產生方式做了調整<span style="font-family: "Times New Roman", serif;">,</span>並讓<span style="font-family: "Times New Roman", serif;">kthreadd Task</span>成為使用<span style="font-family: "Times New Roman", serif;">kthread_create</span>產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>統一的父行程<span style="font-family: "Times New Roman", serif;">. </span>也因此<span style="font-family: "Times New Roman", serif;">,</span>在這機制實現下的<span style="font-family: "Times New Roman", serif;">Linux Kernel,</span>屬於<span style="font-family: "Times New Roman", serif;">User Mode</span>行程最上層的父行程為<span style="font-family: "Times New Roman", serif;">init Task (PID=1),</span>而屬於<span style="font-family: "Times New Roman", serif;">Kernel Mode</span>行程最上層的父行程為 <span style="font-family: "Times New Roman", serif;">kthreadd Task (PID=2),</span>而這兩個行程共同的父行程就是 <span style="font-family: "Times New Roman", serif;">idle Task (PID=0).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>kthreadd</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">kthreadd Kernel Thread</span>主要實作在檔案<span style="font-family: "Times New Roman", serif;">kernel/kthread.c</span>中<span style="font-family: "Times New Roman", serif;">,</span>入口函式為<span style="font-family: "Times New Roman", serif;">kthreadd (</span>宣告為 <span style="font-family: "Times New Roman", serif;">int kthreadd(void *unused) ),</span>主要負責的工作是檢視目前<span style="font-family: "Times New Roman", serif;">Linked List Queue “kthread_create_list”</span>是否有要產生<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的需求<span style="font-family: "Times New Roman", serif;">,</span>若有<span style="font-family: "Times New Roman", serif;">,</span>就呼叫函式<span style="font-family: "Times New Roman", serif;">create_kthread</span>進行後續的產生工作<span style="font-family: "Times New Roman", serif;">. </span>而要透過<span style="font-family: "Times New Roman", serif;">kthreadd </span>產生<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>需求<span style="font-family: "Times New Roman", serif;">,</span>就可以透過呼叫<span style="font-family: "Times New Roman", serif;">kthread_create (</span>與其他衍生的<span style="font-family: "Times New Roman", serif;">kthread</span>函式<span style="font-family: "Times New Roman", serif;">,ex:kthread_create_on_node….etc.)</span>把需求加入到<span style="font-family: "Times New Roman", serif;">Linked List Queue “kthread_create_list”</span>中<span style="font-family: "Times New Roman", serif;">,</span>並<span style="font-family: "Times New Roman", serif;">WakeUp kthreadd Task,</span>就可以使用目前<span style="font-family: "Times New Roman", serif;">kthreadd</span>新設計的機制<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關函式 <span style="font-family: "Times New Roman", serif;">kthreadd</span>內部的運作流程<span style="font-family: "Times New Roman", serif;">,</span>概述如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>執行<span style="font-family: "Times New Roman", serif;">set_task_comm(tsk, “kthreadd”),</span>設定<span style="font-family: "Times New Roman", serif;">Task</span>的執行檔名稱<span style="font-family: "Times New Roman", serif;">,</span>會把<span style="font-family: "Times New Roman", serif;">“kthreadd”</span>複製給<span style="font-family: "Times New Roman", serif;">task_struct</span>中的 <span style="font-family: "Times New Roman", serif;">comm (struct task_struct</span>宣告在 <span style="font-family: "Times New Roman", serif;">include/linux/sched.h).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,</span>執行<span style="font-family: "Times New Roman", serif;">ignore_signals(tsk) ,</span>其中 <span style="font-family: "Times New Roman", serif;">tsk = current,</span>會設定讓<span style="font-family: "Times New Roman", serif;">Task kthreadd </span>忽略所有的<span style="font-family: "Times New Roman", serif;">Signals</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>設定<span style="font-family: "Times New Roman", serif;">kthreadd</span>可以在所有處理器上執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,</span>進入<span style="font-family: "Times New Roman", serif;">kthreadd</span>的 <span style="font-family: "Times New Roman", serif;">for(;;) </span>無窮迴圈<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4-1,</span>透過函式<span style="font-family: "Times New Roman", serif;">list_empty</span>確認<span style="font-family: "Times New Roman", serif;">kthread_create_list</span>是否為空<span style="font-family: "Times New Roman", serif;">,</span>若為空<span style="font-family: "Times New Roman", serif;">,</span>就觸發<span style="font-family: "Times New Roman", serif;">Task</span>排程</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4-2,</span>透過<span style="font-family: "Times New Roman", serif;">list_entry,</span>取出要產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread </span>的”<span style="font-family: "Times New Roman", serif;">struct kthread_create_info” Pointer</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4-3,</span>呼叫<span style="font-family: "Times New Roman", serif;">create_kthread</span>產生<span style="font-family: "Times New Roman", serif;">Kernel Thread.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4-3-1,</span>在<span style="font-family: "Times New Roman", serif;">create_kthread</span>中會以<span style="font-family: "Times New Roman", serif;">“pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);”</span>呼叫函式<span style="font-family: "Times New Roman", serif;">kernel_thread (in arch/arm/kernel/process.c),</span>其中<span style="font-family: "Times New Roman", serif;">,</span>入口函式為<span style="font-family: "Times New Roman", serif;">kthread,</span>新產生的<span style="font-family: "Times New Roman", serif;">Task</span>的第一個函式參數為<span style="font-family: "Times New Roman", serif;">create.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4-3-1-1,</span>在函式<span style="font-family: "Times New Roman", serif;">kernel_thread</span>中<span style="font-family: "Times New Roman", serif;">,</span>會執行如下的程式碼<span style="font-family: "Times New Roman", serif;">,</span>把最後新產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>入口函式指給新<span style="font-family: "Times New Roman", serif;">Task</span>的暫存器<span style="font-family: "Times New Roman", serif;">r5,</span>要傳遞給該入口函式的變數只給暫存器<span style="font-family: "Times New Roman", serif;">r4,</span>而該入口函式結束時要返回的函式<span style="font-family: "Times New Roman", serif;">kernel_thread_exit</span>位址指給暫存器<span style="font-family: "Times New Roman", serif;">r7,</span>並透過透過<span style="font-family: "Times New Roman", serif;">do_fork</span>產生新的行程時<span style="font-family: "Times New Roman", serif;">,</span>暫存器<span style="font-family: "Times New Roman", serif;">PC (Program Counter)</span>指向函式<span style="font-family: "Times New Roman", serif;">kernel_thread_helper. </span>也就是說每一個<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的第一個函式統一都是 <span style="font-family: "Times New Roman", serif;">kernel_thread_helper,</span>而結束函式統一都為<span style="font-family: "Times New Roman", serif;">kernel_thread_exit. </span>函式 <span style="font-family: "Times New Roman", serif;">kernel_thread</span>的參考程式碼如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">/*</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">* Create a kernel thread.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">*/</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct pt_regs regs;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">memset(&regs, 0, sizeof(regs));</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">regs.ARM_r4 = (unsigned long)arg;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">regs.ARM_r5 = (unsigned long)fn;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">regs.ARM_r6 = (unsigned long)kernel_thread_exit;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">regs.ARM_r7 = SVC_MODE | PSR_ENDSTATE | PSR_ISETSTATE;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">regs.ARM_pc = (unsigned long)kernel_thread_helper;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">regs.ARM_cpsr = regs.ARM_r7 | PSR_I_BIT;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
新產生的<span style="font-family: "Times New Roman", serif;">Task</span>會執行函式<span style="font-family: "Times New Roman", serif;">kernel_thread_helper,</span>並把結束函式由暫存器<span style="font-family: "Times New Roman", serif;">r6</span>指給暫存器<span style="font-family: "Times New Roman", serif;">LR(Linker Register),</span>把入口函式的第一個參數指給暫存器<span style="font-family: "Times New Roman", serif;">r0,</span>新<span style="font-family: "Times New Roman", serif;">Task</span>的入口函式由暫存器<span style="font-family: "Times New Roman", serif;">r5</span>指給暫存器<span style="font-family: "Times New Roman", serif;">PC,</span>開始新<span style="font-family: "Times New Roman", serif;">Task</span>的執行<span style="font-family: "Times New Roman", serif;">.</span>有關函式 <span style="font-family: "Times New Roman", serif;">kernel_thread_helper</span>的參考程式碼如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">extern void kernel_thread_helper(void);</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">asm( “.pushsection .text\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” .align\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” .type kernel_thread_helper, #function\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">“kernel_thread_helper:\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#ifdef CONFIG_TRACE_IRQFLAGS</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” bl trace_hardirqs_on\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#endif</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” msr cpsr_c, r7\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” mov r0, r4\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” mov lr, r6\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” mov pc, r5\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” .size kernel_thread_helper, . – kernel_thread_helper\n”</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">” .popsection”);</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於新<span style="font-family: "Times New Roman", serif;">Task</span>的入口函式統一為<span style="font-family: "Times New Roman", serif;">“kthread”,</span>第一個函式參數統一為”<span style="font-family: "Times New Roman", serif;">struct kthread_create_info *create”,</span>檢視函式<span style="font-family: "Times New Roman", serif;">kthread</span>的實作<span style="font-family: "Times New Roman", serif;">,</span>可以看到在新行程由<span style="font-family: "Times New Roman", serif;">kernel_thread_helper</span>呼叫進入<span style="font-family: "Times New Roman", serif;">kthread</span>後<span style="font-family: "Times New Roman", serif;">,</span>就會執行函式參數<span style="font-family: "Times New Roman", serif;">create</span>中的<span style="font-family: "Times New Roman", serif;">create->threadfn</span>函式指標<span style="font-family: "Times New Roman", serif;">,</span>執行其他應用透過<span style="font-family: "Times New Roman", serif;">kthread_create </span>產生<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>時的最終函式入口<span style="font-family: "Times New Roman", serif;">,</span>參考代碼如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">static int kthread(void *_create)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">/* Copy data: it’s on kthread’s stack */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct kthread_create_info *create = _create;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">int (*threadfn)(void *data) = create->threadfn;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">void *data = create->data;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #ff3366;">…<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">…………………..</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret = -EINTR;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">if (!self.should_stop)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret = </span><span style="color: #ff3366;"><span style="font-size: small;"><strong>threadfn</strong></span></span><span style="font-size: xx-small;">(data);</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">/* we can’t just return, we must preserve “self” on stack */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">do_exit(ret);</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關<span style="font-family: "Times New Roman", serif;">kthreadd</span>整體運作的概念<span style="font-family: "Times New Roman", serif;">,</span>可參考下圖</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgEPW6V1CrBuBBcn_Nea5QYNHJmp8FFEKBfuywCFCaCOztXfIcDgv_nh9pfoHQRGpveXziFOB9PwELwufzjTAL66govgQmcmkdEZwq4r5AVcRY_-rXN8AbiI3ASS-mJ8pq3ljOKzlx95E/s1600/LinuxKernelMultiProcessorBooting4_html_m7e78c1c9%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="466" data-original-width="642" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgEPW6V1CrBuBBcn_Nea5QYNHJmp8FFEKBfuywCFCaCOztXfIcDgv_nh9pfoHQRGpveXziFOB9PwELwufzjTAL66govgQmcmkdEZwq4r5AVcRY_-rXN8AbiI3ASS-mJ8pq3ljOKzlx95E/s1600/LinuxKernelMultiProcessorBooting4_html_m7e78c1c9%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>kthread_create vs kernel_thread</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">kernel_thread</span>函式<span style="font-family: "Times New Roman", serif;">,</span>是<span style="font-family: "Times New Roman", serif;">kthreadd</span>機制產生前<span style="font-family: "Times New Roman", serif;">,</span>要使用<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>主要的方式<span style="font-family: "Times New Roman", serif;">,</span>而根據前述的介紹<span style="font-family: "Times New Roman", serif;">,</span>可以看到其實<span style="font-family: "Times New Roman", serif;">kthread_create</span>也是透過函式<span style="font-family: "Times New Roman", serif;">kernel_thread</span>實現<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果我們選擇直接透過<span style="font-family: "Times New Roman", serif;">kernel_thread</span>產生<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>跟透過<span style="font-family: "Times New Roman", serif;">kthreadd</span>機制相比<span style="font-family: "Times New Roman", serif;">,</span>兩者的差別在於<span style="font-family: "Times New Roman", serif;">,</span>一個是由當下呼叫的<span style="font-family: "Times New Roman", serif;">kernel_thread</span>的<span style="font-family: "Times New Roman", serif;">Task</span>行程所<span style="font-family: "Times New Roman", serif;">fork</span>出來的<span style="font-family: "Times New Roman", serif;">,</span>採用<span style="font-family: "Times New Roman", serif;">kthread_create</span>機制則是由<span style="font-family: "Times New Roman", serif;">kthreadd Task</span>行程所<span style="font-family: "Times New Roman", serif;">fork</span>出來的<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行指令 <span style="font-family: "Times New Roman", serif;">ps -axjf </span>可看到如下結果</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 2 0 0 ? -1 S 0 0:00 [kthreadd]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 3 0 0 ? -1 S 0 0:00 \_ [ksoftirqd/0]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 4 0 0 ? -1 S 0 0:01 \_ [kworker/0:0]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 5 0 0 ? -1 S 0 0:00 \_ [kworker/u:0]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 6 0 0 ? -1 S 0 0:00 \_ [migration/0]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 7 0 0 ? -1 S 0 0:00 \_ [migration/1]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 8 0 0 ? -1 S 0 0:00 \_ [kworker/1:0]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 9 0 0 ? -1 S 0 0:00 \_ [ksoftirqd/1]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 10 0 0 ? -1 S 0 0:01 \_ [kworker/0:1]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 11 0 0 ? -1 S< 0 0:00 \_ [khelper]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 12 0 0 ? -1 S< 0 0:00 \_ [netns]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 13 0 0 ? -1 S 0 0:00 \_ [sync_supers]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 14 0 0 ? -1 S 0 0:00 \_ [bdi-default]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 15 0 0 ? -1 S< 0 0:00 \_ [kblockd]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 16 0 0 ? -1 S< 0 0:00 \_ [kacpid]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 17 0 0 ? -1 S< 0 0:00 \_ [kacpi_notify]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 18 0 0 ? -1 S< 0 0:00 \_ [kacpi_hotplug]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 19 0 0 ? -1 S 0 0:00 \_ [khubd]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 20 0 0 ? -1 S< 0 0:00 \_ [md]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 21 0 0 ? -1 S 0 0:00 \_ [khungtaskd]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 22 0 0 ? -1 S 0 0:00 \_ [kswapd0]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 23 0 0 ? -1 S 0 0:00 \_ [fsnotify_mark]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以知道<span style="font-family: "Times New Roman", serif;">,</span>透過<span style="font-family: "Times New Roman", serif;">kthreadd</span>所產生的<span style="font-family: "Times New Roman", serif;">Thread</span>都會是以<span style="font-family: "Times New Roman", serif;">kthreadd</span>為<span style="font-family: "Times New Roman", serif;">Parent</span>的<span style="font-family: "Times New Roman", serif;">Task,</span>跟原本透過<span style="font-family: "Times New Roman", serif;">kernel_thread</span>所產生的<span style="font-family: "Times New Roman", serif;">Task</span>是源自於各自的<span style="font-family: "Times New Roman", serif;">Tasks</span>是有所不同的<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示為透過<span style="font-family: "Times New Roman", serif;">kernel_thread</span>所自行產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>在<span style="font-family: "Times New Roman", serif;">insmod</span>指令結束後<span style="font-family: "Times New Roman", serif;">,</span>這個<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的<span style="font-family: "Times New Roman", serif;">Parent Task</span>為 <span style="font-family: "Times New Roman", serif;">PID=1 (</span>也就是 <span style="font-family: "Times New Roman", serif;">init Task.).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">..</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1 2122 2118 1987 pts/0 2126 R 0 0:21 insmod hello.ko</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>透過</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>kthreadd</strong></span></span><span style="font-size: small;"><strong>的相關函式</strong></span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 647px;"><colgroup><col width="167"></col><col width="462"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="167">函式名稱</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="462">說明</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="167"><span style="font-family: "Times New Roman", serif;">kthread_create_on_node</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="462">宣告為<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">void *data,</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">int node,</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const char namefmt[],</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以產生與命名<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>並可在支援<span style="font-family: "Times New Roman", serif;">NUMA</span>(<span style="font-family: "Times New Roman", serif;">Non-Uniform Memory Access Architecture</span>)的核心下<span style="font-family: "Times New Roman", serif;">,</span>透過<span style="font-family: "Times New Roman", serif;">node</span>可以設定要在哪個處理器上執行所產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread. (</span>會透過設定<span style="font-family: "Times New Roman", serif;">task->pref_node_fork),</span>產生後的行程會等待被函式<span style="font-family: "Times New Roman", serif;">wake_up_process</span>喚醒或是被<span style="font-family: "Times New Roman", serif;">kthread_stop</span>所終止<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="167"><span style="font-family: "Times New Roman", serif;">kthread_create</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="462">參考檔案<span style="font-family: "Times New Roman", serif;">include/linux/kthread.h,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式<span style="font-family: "Times New Roman", serif;">kthread_create</span>的宣告如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#define kthread_create(threadfn, data, namefmt, arg…) \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以看到<span style="font-family: "Times New Roman", serif;">,kthread_create</span>也是透過<span style="font-family: "Times New Roman", serif;">kthread_create_on_node</span>實現<span style="font-family: "Times New Roman", serif;">,</span>差異在於<span style="font-family: "Times New Roman", serif;">node</span>值為<span style="font-family: "Times New Roman", serif;">-1,</span>也就是可以在所有處理器上運作<span style="font-family: "Times New Roman", serif;">,</span>產生後的行程會等待被函式<span style="font-family: "Times New Roman", serif;">wake_up_process</span>喚醒或是被<span style="font-family: "Times New Roman", serif;">kthread_stop</span>所終止<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="167"><span style="font-family: "Times New Roman", serif;">kthread_run</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="462">參考檔案<span style="font-family: "Times New Roman", serif;">include/linux/kthread.h,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式<span style="font-family: "Times New Roman", serif;">kthread_run</span>的宣告如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#define kthread_run(threadfn, data, namefmt, …) \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">({ \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct task_struct *__k \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">= kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">if (!IS_ERR(__k)) \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">wake_up_process(__k); \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">__k; \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">})</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
主要用以產生並喚醒<span style="font-family: "Times New Roman", serif;">Kernel Thread. (</span>開發者可以省去要呼叫<span style="font-family: "Times New Roman", serif;">wake_up_process</span>的動作<span style="font-family: "Times New Roman", serif;">.),</span>且這呼叫是基於<span style="font-family: "Times New Roman", serif;">kthread_create,</span>所以產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>也不限於在特定的處理器上執行<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="167"><span style="font-family: "Times New Roman", serif;">kthread_bind</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="462">綁定<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>到指定的處理器<span style="font-family: "Times New Roman", serif;">,</span>主要是透過設定<span style="font-family: "Times New Roman", serif;">CPU Allowed Bitmask,</span>所以在多核心的架構下<span style="font-family: "Times New Roman", serif;">,</span>就可以指定給一個以上的處理器執行<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="167"><span style="font-family: "Times New Roman", serif;">kthread_stop</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="462">用來暫停透過<span style="font-family: "Times New Roman", serif;">kthread_create</span>產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>會等待<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>結束<span style="font-family: "Times New Roman", serif;">,</span>並傳回函式<span style="font-family: "Times New Roman", serif;">threadfn(=</span>產生<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的函式<span style="font-family: "Times New Roman", serif;">)</span>的返回值<span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過 <span style="font-family: "Times New Roman", serif;">“wait_for_completion(&kthread->exited); ” </span>等待 <span style="font-family: "Times New Roman", serif;">Kernel Thread</span>結束<span style="font-family: "Times New Roman", serif;">,</span>並透過 <span style="font-family: "Times New Roman", serif;">“int ret;….ret = k->exit_code;…..return ret; “</span>取得該結束的<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>返回值<span style="font-family: "Times New Roman", serif;">,</span>傳回給函式<span style="font-family: "Times New Roman", serif;">kthread_stop</span>的呼叫者<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="167"><span style="font-family: "Times New Roman", serif;">kthread_should_stop</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="462">用來在<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>中呼叫<span style="font-family: "Times New Roman", serif;">,</span>如果該值反為<span style="font-family: "Times New Roman", serif;">True,</span>就表示該<span style="font-family: "Times New Roman", serif;">Kernel Thread X</span>有被透過呼叫函式<span style="font-family: "Times New Roman", serif;">kthread_stop</span>指定結束<span style="font-family: "Times New Roman", serif;">,</span>因此<span style="font-family: "Times New Roman", serif;">,Kernel Thread X</span>就必須要準備進行<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的結束流程<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>基於</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>kthreadd</strong></span></span><span style="font-size: small;"><strong>產生的</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Kernel Tasks</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">接下來</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們把在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Linux Kernel</span></span><span style="font-size: x-small;">下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">基於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kthread</span></span><span style="font-size: x-small;">產生的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Kernel Tasks</span></span><span style="font-size: x-small;">做一個概要的介紹</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">藉此可以知道</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Linux Kernel</span></span><span style="font-size: x-small;">有哪些模組基於這機制實現了哪些核心的能力</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">包括檔案系統 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Journaling</span></span><span style="font-size: x-small;">機制</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Inetrrupt BottomHalf,Kernel USB-Hub,Kernel Helper..</span></span><span style="font-size: x-small;">等</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">都是基於這機制下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">所衍生出來的核心實作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">在這段落會頻繁提及的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Work Queue</span></span><span style="font-size: x-small;">可以有兩種實現方式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">分別為</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1, WorkQueue (</span>實作在<span style="font-family: "Times New Roman", serif;">kernel/workqueue.c).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2, </span>產生<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>並搭配 <span style="font-family: "Times New Roman", serif;">Linked List Queue (in include/linux/list.h)</span>機制<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下<span style="font-family: "Times New Roman", serif;">, </span>逐一介紹筆者認為值得說明的<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>與內部機制<span style="font-family: "Times New Roman", serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 647px;"><colgroup><col width="94"></col><col width="536"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;">Kernel Tasks</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">名稱</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;">kworker</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">kernel/workqueue.c,kworker</span>主要提供系統非同步執行的共用<span style="font-family: "Times New Roman", serif;">Worker Pool</span>方案 <span style="font-family: "Times New Roman", serif;">(WorkQueue),</span>一般而言會區分為每個處理器專屬的<span style="font-family: "Times New Roman", serif;">Worker Pool</span>或是屬於整個系統使用的<span style="font-family: "Times New Roman", serif;">Worker Pool</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“<span style="font-family: "Times New Roman", serif;">kworker/A:B”</span>後方的數字意義分別是<span style="font-family: "Times New Roman", serif;">A</span>為 <span style="font-family: "Times New Roman", serif;">CPU ID </span>而<span style="font-family: "Times New Roman", serif;">B</span>為 透過<span style="font-family: "Times New Roman", serif;">ida_get_new</span>配置的<span style="font-family: "Times New Roman", serif;">ID (</span>範圍從 <span style="font-family: "Times New Roman", serif;">0-0x7fffffff).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以筆者雙核心的環境為例<span style="font-family: "Times New Roman", serif;">,</span>以<span style="font-family: "Times New Roman", serif;">CPU#0</span>來說<span style="font-family: "Times New Roman", serif;">,</span>會透過<span style="font-family: "Times New Roman", serif;">kthread_create_on_node</span>產生固定在<span style="font-family: "Times New Roman", serif;">CPU#0</span>上執行的<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">[kworker/0:0],[kworker/0:1],[kworker/1:0]</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">[kworker/1:1].</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">並透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kthread_create</span></span><span style="font-size: x-small;">產生不固定在特定處理器上執行的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">[kworker/u:0]</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">[kworker/u:1].</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
總共呼叫<span style="font-family: "Times New Roman", serif;">create_worker</span>執行六個執行<span style="font-family: "Times New Roman", serif;">gcwq(Global CPU Workqueue) worker thread function</span>的<span style="font-family: "Times New Roman", serif;">Kernel Thread.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 4 0 0 ? -1 S 0 0:01 \_ [kworker/0:0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 5 0 0 ? -1 S 0 0:00 \_ [kworker/u:0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 8 0 0 ? -1 S 0 0:00 \_ [kworker/1:0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 10 0 0 ? -1 S 0 0:00 \_ [kworker/0:1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 30 0 0 ? -1 S 0 0:00 \_ [kworker/1:1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 46 0 0 ? -1 S 0 0:00 \_ [kworker/u:1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">worker_thread</span>為<span style="font-family: "Times New Roman", serif;">WorkQueue</span>機制的核心<span style="font-family: "Times New Roman", serif;">,</span>包括新的<span style="font-family: "Times New Roman", serif;">WorkQueue</span>產生 <span style="font-family: "Times New Roman", serif;">(alloc_workqueue),</span>指派工作到<span style="font-family: "Times New Roman", serif;">WorkQueue(queue_work),</span>把工作指派到特定的處理器<span style="font-family: "Times New Roman", serif;">(queue_work_on),</span>指派工作並設定延遲執行<span style="font-family: "Times New Roman", serif;">(queue_delayed_work),</span>在指定的處理器上指派工作並延遲執行<span style="font-family: "Times New Roman", serif;">(queue_delayed_work_on)..</span>等<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
限於本次預定的篇幅<span style="font-family: "Times New Roman", serif;">,</span>有關<span style="font-family: "Times New Roman", serif;">WorkQueue</span>的進一步討論<span style="font-family: "Times New Roman", serif;">,</span>會在後續文章中介紹<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
需要進一步資訊的開發者<span style="font-family: "Times New Roman", serif;">,</span>可以自行參閱<span style="font-family: "Times New Roman", serif;">Linux Kernel </span>文件<span style="font-family: "Times New Roman", serif;">Documentation/workqueue.txt .</span></div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ksoftirqd</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">kernel/softirq.c,</span>會在每個處理器進入<span style="font-family: "Times New Roman", serif;">CPU_UP_PREPARE</span>或<span style="font-family: "Times New Roman", serif;">CPU_UP_PREPARE_FROZEN</span>狀態時<span style="font-family: "Times New Roman", serif;">,</span>在個別處理器產生<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ksoftirqd Kernel Thread,</span></span><span style="font-size: x-small;">如下所示</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在雙核心環境中會有兩個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Kernel Thread</span></span><span style="font-size: x-small;">各自在兩個處理器上執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 3 0 0 ? -1 S 0 0:00 \_ [ksoftirqd/0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 9 0 0 ? -1 S 0 0:00 \_ [ksoftirqd/1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在<span style="font-family: "Times New Roman", serif;">ksoftirqd Kernel Thread</span>函式<span style="font-family: "Times New Roman", serif;">run_ksoftirqd</span>中<span style="font-family: "Times New Roman", serif;">,</span>會透過</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">“while (!kthread_should_stop()) { …}”</span>迴圈<span style="font-family: "Times New Roman", serif;">,</span>確認目前是否有被執行終止動作<span style="font-family: "Times New Roman", serif;">,</span>若無<span style="font-family: "Times New Roman", serif;">,</span>就往後繼續執行<span style="font-family: "Times New Roman", serif;">. </span>並透過<span style="font-family: "Times New Roman", serif;">local_softirq_pending</span>確認是否有<span style="font-family: "Times New Roman", serif;">Soft IRQ </span>被觸發<span style="font-family: "Times New Roman", serif;">,</span>為了系統效能考量<span style="font-family: "Times New Roman", serif;">,</span>目前<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>會把<span style="font-family: "Times New Roman", serif;">Top Halves </span>放在對應的中斷<span style="font-family: "Times New Roman", serif;">Routine</span>中執行<span style="font-family: "Times New Roman", serif;">,</span>而把屬於<span style="font-family: "Times New Roman", serif;">Bottom Halves </span>的部份透過<span style="font-family: "Times New Roman", serif;">kirqsoftd</span>執行<span style="font-family: "Times New Roman", serif;">. </span>並且在<span style="font-family: "Times New Roman", serif;">ARM</span>多核心的架構下<span style="font-family: "Times New Roman", serif;">,</span>每個處理器都會有自己的<span style="font-family: "Times New Roman", serif;">Local IRQ,</span>因此<span style="font-family: "Times New Roman", serif;">,</span>如果發現有<span style="font-family: "Times New Roman", serif;">Local SoftIRQ</span>待處理<span style="font-family: "Times New Roman", serif;">,</span>就會由各自的處理器對應的<span style="font-family: "Times New Roman", serif;">ksoftirqd Kernel Thread</span>負責執行<span style="font-family: "Times New Roman", serif;">Bottom Halves</span>中的工作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果發現<span style="font-family: "Times New Roman", serif;">,</span>待處理的<span style="font-family: "Times New Roman", serif;">CPU</span>已經<span style="font-family: "Times New Roman", serif;">OffLine</span>也會立刻結束<span style="font-family: "Times New Roman", serif;">ksoftirqd</span>的執行<span style="font-family: "Times New Roman", serif;">. </span>而在<span style="font-family: "Times New Roman", serif;">ksoftirqd</span>中<span style="font-family: "Times New Roman", serif;">,</span>會透過函式<span style="font-family: "Times New Roman", serif;">__do_softirq</span>執行<span style="font-family: "Times New Roman", serif;">SoftIRQ Bottom Halves </span>的工作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若有進一步興趣的開發者<span style="font-family: "Times New Roman", serif;">,</span>也可以參考這篇文章<span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://book.chinaunix.net/special/ebook/oreilly/Understanding_Linux_Network_Internals/0596002556/understandlni-CHP-9-SECT-3.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://book.chinaunix.net/special/ebook/oreilly/Understanding_Linux_Network_Internals/0596002556/understandlni-CHP-9-SECT-3.html</a></span></span> .</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">khelper</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">kernel/kmod.c,</span>在<span style="font-family: "Times New Roman", serif;">Kernel Init</span>的過程中會呼叫函式<span style="font-family: "Times New Roman", serif;">usermodehelper_init,</span>在這函式中就會執行 <span style="font-family: "Times New Roman", serif;">“khelper_wq = create_singlethread_workqueue(“khelper”);”</span>產生<span style="font-family: "Times New Roman", serif;">khelper Kernel Thread.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>執行的過程中<span style="font-family: "Times New Roman", serif;">,</span>就可以透過函式<span style="font-family: "Times New Roman", serif;">call_usermodehelper_exec</span>執行</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">“queue_work(khelper_wq, &sub_info->work);”</span>把工作指派給<span style="font-family: "Times New Roman", serif;">khelper WorkQueue</span>中<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如<span style="font-family: "Times New Roman", serif;">,</span>要載入一個<span style="font-family: "Times New Roman", serif;">Linux Kernel Module</span>時<span style="font-family: "Times New Roman", serif;">,</span>就會透過函式<span style="font-family: "Times New Roman", serif;">__request_module,</span>之後呼叫<span style="font-family: "Times New Roman", serif;">call_usermodehelper_fns</span>並帶入<span style="font-family: "Times New Roman", serif;">modprobe</span>路徑與相關參數作為函式參數<span style="font-family: "Times New Roman", serif;">(</span>函式<span style="font-family: "Times New Roman", serif;">call_usermodehelper_fns</span>的<span style="font-family: "Times New Roman", serif;">inline</span>實作宣告在<span style="font-family: "Times New Roman", serif;">include/linux/kmod.h</span>中<span style="font-family: "Times New Roman", serif;">),</span>最後會呼叫進入<span style="font-family: "Times New Roman", serif;">call_usermodehelper_exec,</span>把工作放到<span style="font-family: "Times New Roman", serif;">khelper WorkQueue</span>中<span style="font-family: "Times New Roman", serif;">,</span>來透過<span style="font-family: "Times New Roman", serif;">khelper Kernel Thread</span>帶起<span style="font-family: "Times New Roman", serif;">User Mode</span>的應用程式執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為<span style="font-family: "Times New Roman", serif;">khelper</span>在筆者環境中產生的行程資訊</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 11 0 0 ? -1 S< 0 0:00 \_ [khelper]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而每一個要放到<span style="font-family: "Times New Roman", serif;">khelper WorkQueue</span>的工作<span style="font-family: "Times New Roman", serif;">,</span>都會透過函式<span style="font-family: "Times New Roman", serif;">call_usermodehelper_setup </span>執行<span style="font-family: "Times New Roman", serif;">“INIT_WORK(&sub_info->work, __call_usermodehelper); ” </span>設定<span style="font-family: "Times New Roman", serif;">WorkQueue</span>要執行的<span style="font-family: "Times New Roman", serif;">Work</span>函式 <span style="font-family: "Times New Roman", serif;">(khelper Work</span>函數固定設為<span style="font-family: "Times New Roman", serif;">__call_usermodehelper),</span>外部執行檔路徑與相關參數<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因此<span style="font-family: "Times New Roman", serif;">,</span>一旦<span style="font-family: "Times New Roman", serif;">khelper Kernel Thread</span>從<span style="font-family: "Times New Roman", serif;">WorkQueue</span>中執行到新工作時<span style="font-family: "Times New Roman", serif;">,</span>就會呼叫函式<span style="font-family: "Times New Roman", serif;">__call_usermodehelper,</span>最後透過函式<span style="font-family: "Times New Roman", serif;">____call_usermodehelper,</span>執行核心函式<span style="font-family: "Times New Roman", serif;">kernel_execve,</span>來達成執行<span style="font-family: "Times New Roman", serif;">User-Mode </span>應用程式的目的<span style="font-family: "Times New Roman", serif;">. <span style="color: #ff3333;"><span style="font-size: xx-small;"><span style="text-decoration-line: underline;"><strong>(</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>這也就是如何由核心去執行外部的 </strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Linux Device Driver Module</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>工具的執行路徑</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>,</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>清楚</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>khelper</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>的行為與機制</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>,</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>對了解</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Linux Drivers</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>載入</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>/</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>運作原理會很有幫助</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>.)</strong></span></span></span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kblockd</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">block/blk-core.c,</span>如同<span style="font-family: "Times New Roman", serif;">khelper,</span>這同樣是透過<span style="font-family: "Times New Roman", serif;">WorkQueue</span>產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>在<span style="font-family: "Times New Roman", serif;">init Call</span>中呼叫<span style="font-family: "Times New Roman", serif;">genhd_device_init</span>函式時<span style="font-family: "Times New Roman", serif;">,</span>會執行<span style="font-family: "Times New Roman", serif;">blk_dev_init</span>並執行 <span style="font-family: "Times New Roman", serif;">“kblockd_workqueue = alloc_workqueue(“kblockd”,WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);” </span>產生<span style="font-family: "Times New Roman", serif;">kblockd Kernel Thread.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為<span style="font-family: "Times New Roman", serif;">kblockd</span>在筆者環境中產生的行程資訊</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 15 0 0 ? -1 S< 0 0:00 \_ [kblockd]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在系統運作過程中<span style="font-family: "Times New Roman", serif;">,</span>可透過<span style="font-family: "Times New Roman", serif;">blk_delay_queue/blk_run_queue_async/kblockd_schedule_work/kblockd_schedule_delayed_work</span>對<span style="font-family: "Times New Roman", serif;">kblockd WorkQueue</span>進行工作的指派<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kseriod</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">drivers/input/serio/serio.c,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考<span style="font-family: "Times New Roman", serif;">Kernel Source Code, Serio </span>在<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>是對<span style="font-family: "Times New Roman", serif;">“Serial I/O “</span>周邊的支援模組<span style="font-family: "Times New Roman", serif;">,</span>只要有使用到<span style="font-family: "Times New Roman", serif;">Serial I/O</span>的輸入裝置<span style="font-family: "Times New Roman", serif;">(Input Device),</span>例如<span style="font-family: "Times New Roman", serif;">:AT keyboard, PS/2 mouse, joysticks</span>搖桿<span style="font-family: "Times New Roman", serif;">..etc </span>都屬此類<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也因此<span style="font-family: "Times New Roman", serif;">,</span>屬於<span style="font-family: "Times New Roman", serif;">Serio</span>的輸入裝置<span style="font-family: "Times New Roman", serif;">,</span>底層就可以包括<span style="font-family: "Times New Roman", serif;">RS232(Com Port),</span>使用<span style="font-family: "Times New Roman", serif;">i8042 Controller</span>晶片的<span style="font-family: "Times New Roman", serif;">AT</span>與<span style="font-family: "Times New Roman", serif;">PS/2 </span>鍵盤<span style="font-family: "Times New Roman", serif;">/</span>滑鼠<span style="font-family: "Times New Roman", serif;">,</span>使用<span style="font-family: "Times New Roman", serif;">ct82c710 Controller</span>晶片的<span style="font-family: "Times New Roman", serif;">QuickPort</span>滑鼠<span style="font-family: "Times New Roman", serif;">…etc. Serio</span>底層可支援的<span style="font-family: "Times New Roman", serif;">Controller</span>很豐富<span style="font-family: "Times New Roman", serif;">,</span>在此只列舉部分底層控制晶片<span style="font-family: "Times New Roman", serif;">,</span>有興趣的開發者請自行參考<span style="font-family: "Times New Roman", serif;">Linux Kernel Source.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
啟動時<span style="font-family: "Times New Roman", serif;">,</span>會在<span style="font-family: "Times New Roman", serif;">Kernel Init</span>執行到<span style="font-family: "Times New Roman", serif;">init Call</span>時呼叫<span style="font-family: "Times New Roman", serif;">serio_init</span>函式<span style="font-family: "Times New Roman", serif;">,</span>並執行<span style="font-family: "Times New Roman", serif;">“serio_task = kthread_run(serio_thread, NULL, “kseriod”);”</span>產生<span style="font-family: "Times New Roman", serif;">kseriod Kernel Thread,</span>以函式<span style="font-family: "Times New Roman", serif;">serio_thread</span>為<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的執行函式</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">static int serio_thread(void *nothing)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">do {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">serio_handle_event();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">wait_event_interruptible(serio_wait,</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kthread_should_stop() || !list_empty(&serio_event_list));</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">} while (!kthread_should_stop());</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">return 0;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
只要<span style="font-family: "Times New Roman", serif;">serio_queue_event</span>被呼叫到<span style="font-family: "Times New Roman", serif;">(</span>像是<span style="font-family: "Times New Roman", serif;">Event SERIO_RESCAN_PORT/SERIO_RECONNECT_CHAIN/SERIO_REGISTER_PORT/SERIO_ATTACH_DRIVER/SERIO_RECONNECT_PORT)</span>就會把<span style="font-family: "Times New Roman", serif;">Add</span>新的<span style="font-family: "Times New Roman", serif;">Event</span>到<span style="font-family: "Times New Roman", serif;">Linked List Queue</span>中<span style="font-family: "Times New Roman", serif;">,</span>並喚醒 <span style="font-family: "Times New Roman", serif;">kseriod Kernel Thread</span>處理對應<span style="font-family: "Times New Roman", serif;">Serio Event.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為<span style="font-family: "Times New Roman", serif;">kseriod</span>在筆者環境中產生的行程資訊</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">USER PID PPID VSIZE RSS WCHAN PC NAME</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">root 9 2 0 0 c018179c 00000000 S kseriod</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kmmcd</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">drivers/mmc/core/core.c,</span>如同<span style="font-family: "Times New Roman", serif;">khelper,</span>這同樣是透過<span style="font-family: "Times New Roman", serif;">WorkQueue</span>產生的<span style="font-family: "Times New Roman", serif;">Kernel Thread,</span>是透過執行<span style="font-family: "Times New Roman", serif;">“workqueue = create_singlethread_workqueue(“kmmcd”);”</span>產生的<span style="font-family: "Times New Roman", serif;">kmmcd Kernel Thread. </span>用以支援<span style="font-family: "Times New Roman", serif;">MMC/SD</span>卡的行為<span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為<span style="font-family: "Times New Roman", serif;">kseriod</span>在筆者環境中產生的行程資訊</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">USER PID PPID VSIZE RSS WCHAN PC NAME</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">root 10 2 0 0 c004b2c4 00000000 S kmmcd</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kswapd</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">mm/vmscan.c,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
啟動時<span style="font-family: "Times New Roman", serif;">,</span>會在<span style="font-family: "Times New Roman", serif;">Kernel Init</span>執行到<span style="font-family: "Times New Roman", serif;">init Call</span>時呼叫<span style="font-family: "Times New Roman", serif;">kswapd_init</span>函式<span style="font-family: "Times New Roman", serif;">,</span>並進入<span style="font-family: "Times New Roman", serif;">kswapd_run</span>後<span style="font-family: "Times New Roman", serif;">,</span>執行<span style="font-family: "Times New Roman", serif;">“pgdat->kswapd = kthread_run(kswapd, pgdat, “kswapd%d”, nid);”</span>產生<span style="font-family: "Times New Roman", serif;">kswapd Kernel Thread,</span>並以函式<span style="font-family: "Times New Roman", serif;">kswapd (</span>宣告<span style="font-family: "Times New Roman", serif;">:static int kswapd(void *p) )</span>為<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的執行函式<span style="font-family: "Times New Roman", serif;">. </span>如下為函式<span style="font-family: "Times New Roman", serif;">kswapd_init</span>的內容<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">swap_setup (in mm/swap.c)</span>之後<span style="font-family: "Times New Roman", serif;">,</span>會透過<span style="font-family: "Times New Roman", serif;">for_each_node_state (in include/linux/nodemask.h),</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">static int __init kswapd_init(void)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">int nid;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">swap_setup();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">for_each_node_state(nid, N_HIGH_MEMORY)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kswapd_run(nid);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">hotcpu_notifier(cpu_callback, 0);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">return 0;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中 <span style="font-family: "Times New Roman", serif;">for_each_node_state</span>宣告如下<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#define for_each_node_state(__node, __state) \</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">for_each_node_mask((__node), node_states[__state])</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對<span style="font-family: "Times New Roman", serif;">Linux</span>而言<span style="font-family: "Times New Roman", serif;">,</span>在多核心的架構下<span style="font-family: "Times New Roman", serif;">,</span>可以支援以<span style="font-family: "Times New Roman", serif;">Node</span>方式去<span style="font-family: "Times New Roman", serif;">Group CPU,</span>也就是說每個<span style="font-family: "Times New Roman", serif;">Node</span>可以擁有一個以上的處理器<span style="font-family: "Times New Roman", serif;">,</span>而在這就會選擇 <span style="font-family: "Times New Roman", serif;">Node</span>的<span style="font-family: "Times New Roman", serif;">HIGH_MEMORY State</span>有被設定的<span style="font-family: "Times New Roman", serif;">Node. </span>也就是說<span style="font-family: "Times New Roman", serif;">,</span>如果該<span style="font-family: "Times New Roman", serif;">CPU Node</span>的<span style="font-family: "Times New Roman", serif;">HIGH_MEMORY State</span>有被設定<span style="font-family: "Times New Roman", serif;">,</span>就會執行<span style="font-family: "Times New Roman", serif;">kswapd_run,</span>並把該<span style="font-family: "Times New Roman", serif;">Node Id</span>帶入成為<span style="font-family: "Times New Roman", serif;">nid</span>的值<span style="font-family: "Times New Roman", serif;">. (</span>也就是最後<span style="font-family: "Times New Roman", serif;">kswapd</span>後面的數字<span style="font-family: "Times New Roman", serif;">).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者對<span style="font-family: "Times New Roman", serif;">Linux Kernel HighMemory</span>的理解是<span style="font-family: "Times New Roman", serif;">,</span>當所配置的實體記憶體大於<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>虛擬記憶體範圍<span style="font-family: "Times New Roman", serif;">(</span>通常在<span style="font-family: "Times New Roman", serif;">ARM</span>上是 <span style="font-family: "Times New Roman", serif;">0xc0000000-0xffffffff</span>這<span style="font-family: "Times New Roman", serif;">1GB</span>的範圍<span style="font-family: "Times New Roman", serif;">),</span>而因為受限於 <span style="font-family: "Times New Roman", serif;">Memory Mapped I/O</span>或實際上的<span style="font-family: "Times New Roman", serif;">Kernel</span>需要<span style="font-family: "Times New Roman", serif;">,</span>有部分所需的實體記憶體無法被<span style="font-family: "Times New Roman", serif;">Mapped</span>到這<span style="font-family: "Times New Roman", serif;">1GB</span>虛擬記憶體空間中<span style="font-family: "Times New Roman", serif;">,</span>此時就會需要<span style="font-family: "Times New Roman", serif;">Kernel Enable High Memory</span>的能力<span style="font-family: "Times New Roman", serif;">. </span>目前在<span style="font-family: "Times New Roman", serif;">ARM Linux Kernel</span>中也有支援<span style="font-family: "Times New Roman", serif;">High Memory,</span>並可針對<span style="font-family: "Times New Roman", serif;">High Memory</span>需求配置<span style="font-family: "Times New Roman", serif;">2nd-level PageTables. </span>在沒開啟<span style="font-family: "Times New Roman", serif;">High Memory</span>的<span style="font-family: "Times New Roman", serif;">Linux Kernel, Node States</span>中<span style="font-family: "Times New Roman", serif;">N_HIGH_MEMORY </span>的值會等於 <span style="font-family: "Times New Roman", serif;">N_NORMAL_MEMORY,</span>也就是會讓<span style="font-family: "Times New Roman", serif;">Normal Memory</span>跟<span style="font-family: "Times New Roman", serif;">High Memory</span>的設定一致<span style="font-family: "Times New Roman", serif;">. </span>一般而言<span style="font-family: "Times New Roman", serif;">,</span>在考慮系統效能時<span style="font-family: "Times New Roman", serif;">,</span>並不建議開啟<span style="font-family: "Times New Roman", serif;">High Memory</span>能力<span style="font-family: "Times New Roman", serif;">. </span>前提也是硬體設計時<span style="font-family: "Times New Roman", serif;">,</span>也要避免遇到這樣的問題<span style="font-family: "Times New Roman", serif;">,</span>如果選擇把<span style="font-family: "Times New Roman", serif;">Kernel Space</span>加大<span style="font-family: "Times New Roman", serif;"><span style="color: #ff3333;"><span style="font-size: xx-small;"><span style="text-decoration-line: underline;"><strong>(</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>例如從</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1G/3G</strong></span></span></span></span><span style="color: #ff3333;"><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>變成</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>2G/2G)</strong></span></span></span>,</span>則會限制到需要大量記憶體應用程式的執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這有一篇關於<span style="font-family: "Times New Roman", serif;">Linux Kernel HighMemory</span>的文章<span style="font-family: "Times New Roman", serif;">,</span>有興趣的開發者也可以參考看看<span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://kerneltrap.org/node/2450" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://kerneltrap.org/node/2450</a></span></span> .</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為<span style="font-family: "Times New Roman", serif;">kswapd</span>在筆者環境中產生的行程資訊</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 22 0 0 ? -1 S 0 0:00 \_ [kswapd0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在<span style="font-family: "Times New Roman", serif;">kswapd Kernel Thread</span>的函式<span style="font-family: "Times New Roman", serif;">kswapd</span>中<span style="font-family: "Times New Roman", serif;">,</span>主要進行縮減 <span style="font-family: "Times New Roman", serif;">Slab Cache (</span>例如檔案系統快取<span style="font-family: "Times New Roman", serif;">),</span>並在<span style="font-family: "Times New Roman", serif;">Free Pages</span>數量過低時<span style="font-family: "Times New Roman", serif;">,</span>把記憶體<span style="font-family: "Times New Roman", serif;">Swap Out</span>到磁碟中<span style="font-family: "Times New Roman", serif;">,</span>會透過函式<span style="font-family: "Times New Roman", serif;">balance_pgdat</span>對每個處理器<span style="font-family: "Times New Roman", serif;">Node<span style="color: #ff3333;"><span style="font-size: xx-small;"><strong>(</strong></span></span></span><span style="color: #ff3333;"><span style="font-size: xx-small;"><strong>這定義是針對多核心的內化設計</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>.)</strong></span></span></span>的記憶體區域<span style="font-family: "Times New Roman", serif;"><span style="color: #ff3333;"><span style="font-size: xx-small;"><strong>(Zone)</strong></span></span></span>進行記憶體釋放<span style="font-family: "Times New Roman", serif;">,</span>直到所有記憶體區域的<span style="font-family: "Times New Roman", serif;">Free Pages</span>都達到<span style="font-family: "Times New Roman", serif;">High WaterMark<span style="color: #ff3333;"><span style="font-size: xx-small;"><strong> (</strong></span></span></span><span style="color: #ff3333;"><span style="font-size: xx-small;"><strong>透過呼叫</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>high_wmark_pages</strong></span></span></span><span style="color: #ff3333;"><span style="font-size: xx-small;"><strong>確認</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>)</strong></span></span>,</span>也就是<span style="font-family: "Times New Roman", serif;"><span style="color: #ff3333;"><strong>“free_pages > high_wmark_pages(zone)”</strong></span>.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考<span style="font-family: "Times New Roman", serif;">include/linux/mmzone.h,</span>有關<span style="font-family: "Times New Roman", serif;">Memory Zone Water Marker</span>相關巨集宣告如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#define min_wmark_pages(z) (z->watermark[WMARK_MIN])</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#define low_wmark_pages(z) (z->watermark[WMARK_LOW])</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#define high_wmark_pages(z) (z->watermark[WMARK_HIGH])</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後<span style="font-family: "Times New Roman", serif;">,</span>附帶補充一下<span style="font-family: "Times New Roman", serif;">,Linux Kernel</span>本身支援在每次透過<span style="font-family: "Times New Roman", serif;">Page Allocate</span>配置記憶體時<span style="font-family: "Times New Roman", serif;">(Source Code</span>在<span style="font-family: "Times New Roman", serif;">mm/page_alloc.c),</span>透過核心的<span style="font-family: "Times New Roman", serif;">OOM</span>模組<span style="font-family: "Times New Roman", serif;">(Source Code </span>在<span style="font-family: "Times New Roman", serif;">mm/oom_kill.c),</span>評估目前記憶體資源是不是快耗盡<span style="font-family: "Times New Roman", serif;">,</span>如果是就會透過函式<span style="font-family: "Times New Roman", serif;">mem_cgroup_out_of_memory</span>呼叫<span style="font-family: "Times New Roman", serif;">select_bad_process</span>選擇一個透過<span style="font-family: "Times New Roman", serif;">badness</span>計算後<span style="font-family: "Times New Roman", serif;">,</span>要被終止的行程<span style="font-family: "Times New Roman", serif;">,</span>然後呼叫函式<span style="font-family: "Times New Roman", serif;">oom_kill_process,</span>最後在函式<span style="font-family: "Times New Roman", serif;">__oom_kill_task</span>中發送<span style="font-family: "Times New Roman", serif;">SIGKILL Signal</span>強制終止行程執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而<span style="font-family: "Times New Roman", serif;">Android</span>本身也有在<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>中加入 <span style="font-family: "Times New Roman", serif;">Low Memory Killer</span>模組<span style="font-family: "Times New Roman", serif;">(</span>並關閉<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>原本的<span style="font-family: "Times New Roman", serif;">OOM),</span>啟動時會透過函式<span style="font-family: "Times New Roman", serif;">register_shrinker(in mm/vmscan.c)</span>註冊自己的<span style="font-family: "Times New Roman", serif;">lowmem_shrinker</span>服務<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kstriped</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">drivers/md/dm-stripe.c,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會在執行<span style="font-family: "Times New Roman", serif;">dm_stripe_init</span>時<span style="font-family: "Times New Roman", serif;">,</span>透過<span style="font-family: "Times New Roman", serif;">“kstriped = create_singlethread_workqueue(“kstriped”);”</span>產生執行 <span style="font-family: "Times New Roman", serif;">WorkQueue </span>的<span style="font-family: "Times New Roman", serif;">kernel Thread,</span>並在函式<span style="font-family: "Times New Roman", serif;">stripe_ctr</span>中透過<span style="font-family: "Times New Roman", serif;">“INIT_WORK(&sc->kstriped_ws, trigger_event);”</span>設定函式 <span style="font-family: "Times New Roman", serif;">trigger_event</span>為<span style="font-family: "Times New Roman", serif;">WorkQueue</span>的<span style="font-family: "Times New Roman", serif;">Work</span>函式<span style="font-family: "Times New Roman", serif;">,</span>並設定相關<span style="font-family: "Times New Roman", serif;">Strip</span>所需參數<span style="font-family: "Times New Roman", serif;">. </span>在函式<span style="font-family: "Times New Roman", serif;">trigger_event</span>中<span style="font-family: "Times New Roman", serif;">,</span>會再呼叫<span style="font-family: "Times New Roman", serif;">dm_table_event(in drivers/md/dm-table.c)</span>然後執行<span style="font-family: "Times New Roman", serif;">event_fn.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MD (Multiple Device)</span>主要用以支援把多個裝置虛擬為單一裝置<span style="font-family: "Times New Roman", serif;">,</span>一般會應用在<span style="font-family: "Times New Roman", serif;">Software RAID </span>或 <span style="font-family: "Times New Roman", serif;">LVM (Logical Volume Management)</span>的功能上<span style="font-family: "Times New Roman", serif;">.</span>同時<span style="font-family: "Times New Roman", serif;">,</span>參考<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>文件<span style="font-family: "Times New Roman", serif;">Documentation/device-mapper/striped.txt, dm-stripe (in Device-Mapper)</span>主要用以支援像是<span style="font-family: "Times New Roman", serif;">RAID0</span>的<span style="font-family: "Times New Roman", serif;">Striped</span>儲存裝置<span style="font-family: "Times New Roman", serif;">,</span>可以把要寫入的資料<span style="font-family: "Times New Roman", serif;">,</span>分割為不同的<span style="font-family: "Times New Roman", serif;">Chunks</span>循序且循環的寫入到多個底層的儲存裝置中<span style="font-family: "Times New Roman", serif;">,</span>由於是把單筆資料分割為不同的<span style="font-family: "Times New Roman", serif;">Chunks</span>個別對多個裝置寫入<span style="font-family: "Times New Roman", serif;">,</span>因此可以大幅改善儲存媒體寫入的效率<span style="font-family: "Times New Roman", serif;">. (</span>相對於只對單一裝置寫入<span style="font-family: "Times New Roman", serif;">,</span>把一筆資料分割後同時對多個裝置寫入可以縮短寫入等待的時間<span style="font-family: "Times New Roman", serif;">).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>的<span style="font-family: "Times New Roman", serif;">Software RAID </span>可支援軟體把多個磁碟<span style="font-family: "Times New Roman", serif;">Partition</span>整合為一個邏輯磁碟<span style="font-family: "Times New Roman", serif;">,</span>並支援像是<span style="font-family: "Times New Roman", serif;">RAID1,4 </span>或<span style="font-family: "Times New Roman", serif;">5,</span>藉此避免硬碟損壞時造成的資料損失<span style="font-family: "Times New Roman", serif;">.</span>不過在重視效能的環境中<span style="font-family: "Times New Roman", serif;">,Hardware RAID</span>還是比較有效率的<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為<span style="font-family: "Times New Roman", serif;">kstriped</span>在筆者環境中產生的行程資訊</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">USER PID PPID VSIZE RSS WCHAN PC NAME</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">root 23 2 0 0 c004b2c4 00000000 S kstriped</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Android</span>本身也有支援對<span style="font-family: "Times New Roman", serif;">Device-Mapper</span>的操作<span style="font-family: "Times New Roman", serif;">,</span>細節就不在本文範圍中<span style="font-family: "Times New Roman", serif;">,</span>各位可以參考<span style="font-family: "Times New Roman", serif;">2.3 Source Code “gingerbread/system/vold/Devmapper.cpp”.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kjournald</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">fs/jbd/journal.c ,</span>會透過執行 <span style="font-family: "Times New Roman", serif;">“t = kthread_run(kjournald, journal, “kjournald”);”,</span>產生支援 <span style="font-family: "Times New Roman", serif;">Ext3 </span>檔案系統<span style="font-family: "Times New Roman", serif;">Journaling</span>的<span style="font-family: "Times New Roman", serif;">Kernel Thread. </span>或參考檔案<span style="font-family: "Times New Roman", serif;">fs/jbd2/journal.c,</span>會透過執行<span style="font-family: "Times New Roman", serif;">“t = kthread_run(kjournald2, journal, “jbd2/%s”,journal->j_devname);”,</span>產生支援<span style="font-family: "Times New Roman", serif;">Ext4</span>與<span style="font-family: "Times New Roman", serif;">OCFS2</span>檔案系統<span style="font-family: "Times New Roman", serif;">,</span>並可延伸支援更大空間<span style="font-family: "Times New Roman", serif;">64 bits block numbers</span>機制的<span style="font-family: "Times New Roman", serif;">Journaling Kernel Thread.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以支援<span style="font-family: "Times New Roman", serif;">Ext3</span>的<span style="font-family: "Times New Roman", serif;">kjournald</span>來說<span style="font-family: "Times New Roman", serif;">,</span>主要負責兩類工作<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,Commit: </span>用以把<span style="font-family: "Times New Roman", serif;">Joirnaling FileSystem</span>所產生的<span style="font-family: "Times New Roman", serif;">MetaData</span>寫回對應的檔案系統位置<span style="font-family: "Times New Roman", serif;">. </span>用以正式的把資料完成寫入動作<span style="font-family: "Times New Roman", serif;">,</span>並可釋出<span style="font-family: "Times New Roman", serif;">MetaData</span>的空間<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,CheckPoint: </span>會由這個<span style="font-family: "Times New Roman", serif;">Thread</span>執行查核點的動作<span style="font-family: "Times New Roman", serif;">,</span>把<span style="font-family: "Times New Roman", serif;">Journaling Log</span>內容回寫<span style="font-family: "Times New Roman", serif;">,</span>以便這些空間可以重複利用<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
啟動流程為<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">Ext3</span>初始化時<span style="font-family: "Times New Roman", serif;">,</span>執行函式<span style="font-family: "Times New Roman", serif;">ext3_create_journal (in fs/ext3/super.c),</span>之後進入函式<span style="font-family: "Times New Roman", serif;">journal_create (in fs/jbd/journal.c)->journal_reset (in fs/jbd/journal.c) ->journal_start_thread (in fs/jbd/journal.c), </span>透過函式<span style="font-family: "Times New Roman", serif;">kthread_run </span>產生<span style="font-family: "Times New Roman", serif;">kjournald Kernel Thread,</span>之後進入 <span style="font-family: "Times New Roman", serif;">“wait_event(journal->j_wait_done_commit, journal->j_task != NULL);” </span>等待<span style="font-family: "Times New Roman", serif;">kjournald Kernel Thread</span>產生完畢<span style="font-family: "Times New Roman", serif;">,</span>呼叫<span style="font-family: "Times New Roman", serif;">“wake_up(&journal->j_wait_done_commit);” </span>讓函式<span style="font-family: "Times New Roman", serif;">journal_start_thread</span>結束執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關<span style="font-family: "Times New Roman", serif;">kjournald</span>會被<span style="font-family: "Times New Roman", serif;">Timer WakeUp</span>起來執行<span style="font-family: "Times New Roman", serif;">Commit</span>的流程<span style="font-family: "Times New Roman", serif;">,</span>其中<span style="font-family: "Times New Roman", serif;">Interval</span>的設定如下 <span style="font-family: "Times New Roman", serif;">“journal->j_commit_interval = (HZ * JBD_DEFAULT_MAX_COMMI</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">T_AGE);” (in fs/jbd/journal.c), </span>而<span style="font-family: "Times New Roman", serif;">HZ</span>為每秒觸發的<span style="font-family: "Times New Roman", serif;">Tick</span>中斷次數<span style="font-family: "Times New Roman", serif;">(</span>在筆者環境為<span style="font-family: "Times New Roman", serif;">100). </span>同時參考檔案 <span style="font-family: "Times New Roman", serif;">“include/linux/jbd.h” </span>中有關<span style="font-family: "Times New Roman", serif;">JBD_DEFAULT_MAX_COMMI</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">T_AGE</span>的設定為<span style="font-family: "Times New Roman", serif;">5. (“#define JBD_DEFAULT_MAX_COMMIT_AGE 5″),</span>也就是說<span style="font-family: "Times New Roman", serif;">kjournald Kernel Thread</span>會被<span style="font-family: "Times New Roman", serif;">Timer</span>喚醒的<span style="font-family: "Times New Roman", serif;">Interval</span>值為<span style="font-family: "Times New Roman", serif;">5</span>秒<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式<span style="font-family: "Times New Roman", serif;">kjournald (</span>原型為 <span style="font-family: "Times New Roman", serif;">“static int kjournald(void *arg)”),</span>為<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的主函式<span style="font-family: "Times New Roman", serif;">,</span>會執行如下的動作<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>設定<span style="font-family: "Times New Roman", serif;">Timer (</span>呼叫<span style="font-family: "Times New Roman", serif;">“setup_timer(&journal->j_commit_timer, commit_timeout,(unsigned long)current);”),</span>固定週期透過<span style="font-family: "Times New Roman", serif;">Callback</span>函式<span style="font-family: "Times New Roman", serif;">commit_timeout</span>喚醒<span style="font-family: "Times New Roman", serif;">kjournald Kernel Thread,</span>進行<span style="font-family: "Times New Roman", serif;">Journaling</span>檔案系統<span style="font-family: "Times New Roman", serif;">Log</span>回寫的動作<span style="font-family: "Times New Roman", serif;">. </span>參考檔案 <span style="font-family: "Times New Roman", serif;">“fs/jbd/transaction.c”,</span>在函式<span style="font-family: "Times New Roman", serif;">get_transaction</span>中<span style="font-family: "Times New Roman", serif;">,</span>會設定<span style="font-family: "Times New Roman", serif;">Expire</span>的時間點為現在的<span style="font-family: "Times New Roman", serif;">Tick</span>值<span style="font-family: "Times New Roman", serif;">jiffies </span>加上<span style="font-family: "Times New Roman", serif;">journal->j_commit_int</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">erval </span>的值 <span style="font-family: "Times New Roman", serif;">(“transaction->t_expires = jiffies + journal->j_commit_interval;”), (</span>在筆者環境<span style="font-family: "Times New Roman", serif;">Interval</span>設定為<span style="font-family: "Times New Roman", serif;">5</span>秒<span style="font-family: "Times New Roman", serif;">.).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,</span>進入<span style="font-family: "Times New Roman", serif;">Loop</span>中<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-1,</span>確認<span style="font-family: "Times New Roman", serif;">journal->j_flags,</span>若狀態<span style="font-family: "Times New Roman", serif;">JFS_UNMOUNT</span>成立<span style="font-family: "Times New Roman", serif;">,</span>就結束<span style="font-family: "Times New Roman", serif;">Loop</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-2,</span>呼叫函式<span style="font-family: "Times New Roman", serif;">journal_commit_transaction (in fs/jbd/commit.c),</span>執行<span style="font-family: "Times New Roman", serif;">Log</span>回寫</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-2-1,……</span>至於回寫機制<span style="font-family: "Times New Roman", serif;">….</span>過於細節<span style="font-family: "Times New Roman", serif;">,</span>就不在這討論了<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-3,</span>喚醒等待<span style="font-family: "Times New Roman", serif;">journal->j_wait_done_commit</span>的行程 <span style="font-family: "Times New Roman", serif;">(</span>等同告知<span style="font-family: "Times New Roman", serif;">Log</span>回寫結束<span style="font-family: "Times New Roman", serif;">.)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-4,</span>確認<span style="font-family: "Times New Roman", serif;">thread_info->flags</span>的<span style="font-family: "Times New Roman", serif;">TIF_FREEZE bit</span>是否為<span style="font-family: "Times New Roman", serif;">1 (TIF_FREEZE=19). (</span>例如可以透過函式<span style="font-family: "Times New Roman", serif;">freeze_task</span>對<span style="font-family: "Times New Roman", serif;">Task</span>發出<span style="font-family: "Times New Roman", serif;">freeze request ).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-4-1,</span>若上述成立<span style="font-family: "Times New Roman", serif;">,</span>就會進入函式<span style="font-family: "Times New Roman", serif;">refrigerator (in kernel/freezer.c),</span>並進入<span style="font-family: "Times New Roman", serif;">for(;;)</span>迴圈中<span style="font-family: "Times New Roman", serif;">,</span>直到<span style="font-family: "Times New Roman", serif;">frozen(current)</span>不成立<span style="font-family: "Times New Roman", serif;">,</span>才會結束迴圈<span style="font-family: "Times New Roman", serif;">,</span>把函式執行完畢<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-5,</span>反之<span style="font-family: "Times New Roman", serif;">,</span>若<span style="font-family: "Times New Roman", serif;">2-4</span>條件不成立<span style="font-family: "Times New Roman", serif;">,</span>就會等待<span style="font-family: "Times New Roman", serif;">journal->j_wait_commit Wait Event,</span>或判斷是否可以進入等待<span style="font-family: "Times New Roman", serif;">,</span>例如還有待回寫的<span style="font-family: "Times New Roman", serif;">Log</span>沒有執行完畢 <span style="font-family: "Times New Roman", serif;">(“if (journal->j_commit_sequence != journal->j_commit_request) “),</span>或有執行中的<span style="font-family: "Times New Roman", serif;">Transaction</span>且現在的系統<span style="font-family: "Times New Roman", serif;">Tick</span>值已經大於等於原本<span style="font-family: "Times New Roman", serif;">kjournald</span>所設定的<span style="font-family: "Times New Roman", serif;">Timer</span>要觸發<span style="font-family: "Times New Roman", serif;">TimeOut</span>的時間值 <span style="font-family: "Times New Roman", serif;">(</span>也就是說已經發生過<span style="font-family: "Times New Roman", serif;">TimeOut</span>了<span style="font-family: "Times New Roman", serif;">),</span>若上述條件成立<span style="font-family: "Times New Roman", serif;">,</span>就會讓系統繼續執行下去<span style="font-family: "Times New Roman", serif;">,</span>而不進入等待<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-6,kjournald</span>處於執行狀態 <span style="font-family: "Times New Roman", serif;">(</span>有可能是因為 <span style="font-family: "Times New Roman", serif;">TimeOut</span>或是<span style="font-family: "Times New Roman", serif;">journal->j_wait_commit Wait Event</span>喚醒<span style="font-family: "Times New Roman", serif;">),</span>透過比對現在的<span style="font-family: "Times New Roman", serif;">Tick</span>值是否大於等於<span style="font-family: "Times New Roman", serif;">Timer TimeOut</span>值<span style="font-family: "Times New Roman", serif;">(transaction->t_expires),</span>確認是否為透過 <span style="font-family: "Times New Roman", serif;">Timer</span>喚醒<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2-7,</span>重複回到<span style="font-family: "Times New Roman", serif;">2-1,</span>繼續<span style="font-family: "Times New Roman", serif;">kjournald Kernel Thread</span>的執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考下圖<span style="font-family: "Times New Roman", serif;">,</span>為整個<span style="font-family: "Times New Roman", serif;">kjournald Kernel Thread</span>與 <span style="font-family: "Times New Roman", serif;">Timer</span>運作的示意圖<span style="font-family: "Times New Roman", serif;">.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdp0PFBabBIT6z2RYsbBXNJyOCk4_AiCv2HYjAv95iu3SbHWcSMXKCw07uK6hcevHdUq71aEO07zYHW_7dOTnj6SEWLFeLDwemwygnDJyHwMI49QO8GoJwWsKvB2UjdBSWpukw7g7CFbA/s1600/LinuxKernelMultiProcessorBooting4_html_4bfbdcac%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="381" data-original-width="534" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdp0PFBabBIT6z2RYsbBXNJyOCk4_AiCv2HYjAv95iu3SbHWcSMXKCw07uK6hcevHdUq71aEO07zYHW_7dOTnj6SEWLFeLDwemwygnDJyHwMI49QO8GoJwWsKvB2UjdBSWpukw7g7CFbA/s1600/LinuxKernelMultiProcessorBooting4_html_4bfbdcac%255B1%255D.gif" /></a></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">events</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">kernel/workqueue.c,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">events Kernel Thread</span>主要提供核心延後工作執行的方式<span style="font-family: "Times New Roman", serif;">,</span>如前述的實作介紹<span style="font-family: "Times New Roman", serif;">,</span>有的應用會透過自己建立的<span style="font-family: "Times New Roman", serif;">WorkQueue</span>來實現這樣的設計<span style="font-family: "Times New Roman", serif;">,</span>或是也可以透過<span style="font-family: "Times New Roman", serif;">Global WorkQueue</span>來達成目的<span style="font-family: "Times New Roman", serif;">,</span>在啟動過程中會透過函式 <span style="font-family: "Times New Roman", serif;">init_workqueues</span>來初始化 <span style="font-family: "Times New Roman", serif;">keventd_wq (</span>也就是<span style="font-family: "Times New Roman", serif;">keventd WorkQueue).</span>參考如下程式碼<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">void __init init_workqueues(void)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">..</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><span style="font-size: xx-small;"><strong>keventd_wq = create_workqueue(“events”);</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當有需要使用預設的<span style="font-family: "Times New Roman", serif;">WorkQueue</span>時<span style="font-family: "Times New Roman", serif;">,</span>可以透過函式<span style="font-family: "Times New Roman", serif;">schedule_work,</span>把要處理的工作放到<span style="font-family: "Times New Roman", serif;">Global Work Queue,</span>這函式參考實作如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">int schedule_work(struct work_struct *work)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">return queue_work(keventd_wq, work);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果希望放到<span style="font-family: "Times New Roman", serif;">Global WorkQueue</span>並加入<span style="font-family: "Times New Roman", serif;">Delayed</span>值<span style="font-family: "Times New Roman", serif;">,</span>可以透過函式<span style="font-family: "Times New Roman", serif;">schedule_delayed_work ,</span>參考實作如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">int schedule_delayed_work(struct delayed_work *dwork,</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">unsigned long delay)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">return queue_delayed_work(keventd_wq, dwork, delay);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或透過函式<span style="font-family: "Times New Roman", serif;">schedule_work_on </span>把工作指派到指定的處理器上<span style="font-family: "Times New Roman", serif;">,</span>參考實作如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">int schedule_work_on(int cpu, struct work_struct *work)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">return queue_work_on(cpu, keventd_wq, work);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也可以透過函式<span style="font-family: "Times New Roman", serif;">schedule_delayed_work_on </span>指定在所要的處理器上<span style="font-family: "Times New Roman", serif;">,</span>並附帶<span style="font-family: "Times New Roman", serif;">Delayed</span>值<span style="font-family: "Times New Roman", serif;">,</span>參考實作如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">int schedule_delayed_work_on(int cpu,</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct delayed_work *dwork, unsigned long delay)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">return queue_delayed_work_on(cpu, keventd_wq, dwork, delay);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有興趣的開發者<span style="font-family: "Times New Roman", serif;">,</span>也可以參考這篇<span style="font-family: "Times New Roman", serif;">Linux Kernel Korner</span>文章 <span style="font-family: "Times New Roman", serif;">“Kernel Korner – The New Work Queue Interface in the 2.6 Kernel” (in<span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://www.linuxjournal.com/article/6916" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.linuxjournal.com/article/6916</a></span></span> )</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">pdflush</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">mm/pdflush.c,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">pdflush</span>主要的工作為把由檔案系統<span style="font-family: "Times New Roman", serif;">Mapping</span>到記憶體的內容為<span style="font-family: "Times New Roman", serif;">Dirty</span>的<span style="font-family: "Times New Roman", serif;">Pages,</span>負責回寫到檔案系統中<span style="font-family: "Times New Roman", serif;">. </span>可以透過設定<span style="font-family: "Times New Roman", serif;">/proc/sys/vm/dirty_background_ratio</span>決定當<span style="font-family: "Times New Roman", serif;">Dirty Pages</span>超過多少比率時<span style="font-family: "Times New Roman", serif;">,</span>便執行回寫到檔案系統的動作<span style="font-family: "Times New Roman", serif;">.(</span>在筆者的環境中為<span style="font-family: "Times New Roman", serif;">10%).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在運作時<span style="font-family: "Times New Roman", serif;">,</span>會透過函式 <span style="font-family: "Times New Roman", serif;">start_one_pdflush_thread</span>產生 <span style="font-family: "Times New Roman", serif;">pdflush Krnel Thread,</span>參考如下程式碼</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">static void start_one_pdflush_thread(void)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct task_struct *k;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">k = kthread_run(pdflush, NULL, “pdflush”);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">if (unlikely(IS_ERR(k))) {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">spin_lock_irq(&pdflush_lock);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">nr_pdflush_threads–;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">spin_unlock_irq(&pdflush_lock);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並可視目前執行回寫動作忙碌的情況<span style="font-family: "Times New Roman", serif;">,</span>再透過函式<span style="font-family: "Times New Roman", serif;">start_one_pdflush_thread</span>產生新的<span style="font-family: "Times New Roman", serif;">pdflush Kernel Thread. (</span>總量不超過<span style="font-family: "Times New Roman", serif;">MAX_PDFLUSH_THREADS).</span></div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"><span style="font-family: "Times New Roman", serif;">Migration</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536">參考檔案<span style="font-family: "Times New Roman", serif;">kernel/stop_machine.c,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在多核心的架構下<span style="font-family: "Times New Roman", serif;">,Migration</span>在意義上主要是讓運作在處理器<span style="font-family: "Times New Roman", serif;">#A</span>的行程可以轉移到處理器<span style="font-family: "Times New Roman", serif;">#B</span>或其它處理器上<span style="font-family: "Times New Roman", serif;">.</span>但在目前筆者使用的<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>中<span style="font-family: "Times New Roman", serif;">,Migration</span>主要為當處理器進行<span style="font-family: "Times New Roman", serif;">CPU Down</span>流程時<span style="font-family: "Times New Roman", serif;">,</span>負責執行<span style="font-family: "Times New Roman", serif;">Callback</span>函式<span style="font-family: "Times New Roman", serif;">,</span>讓屬於要停止的處理器上的<span style="font-family: "Times New Roman", serif;">Tasks</span>可以轉移到還能持續運作的處理器上<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Migration Kernel Thread</span>主要的任務為在多核心的架構下<span style="font-family: "Times New Roman", serif;">,</span>支援<span style="font-family: "Times New Roman", serif;">Stop CPU</span>的行為<span style="font-family: "Times New Roman", serif;">,</span>也因此可以視這個<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>為<span style="font-family: "Times New Roman", serif;">Stopper Kernel Thread,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當處理器進行<span style="font-family: "Times New Roman", serif;">CPU Down</span>時<span style="font-family: "Times New Roman", serif;">,</span>就會透過這個<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>呼叫所指定<span style="font-family: "Times New Roman", serif;">Callback Functions.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如之前介紹到的其它模組<span style="font-family: "Times New Roman", serif;">,</span>在多核心的處理器上<span style="font-family: "Times New Roman", serif;">,</span>會產生對應的 <span style="font-family: "Times New Roman", serif;">Migration Kernel Thread,</span>例如<span style="font-family: "Times New Roman", serif;">: [migration/0] </span>與 <span style="font-family: "Times New Roman", serif;">[migration/1].</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>1,</strong></span></span><span style="color: red;"><strong>當新執行的應用程式</strong><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span></span><span style="color: red;"><strong>被分配到的處理器跟目前所在處理器不同時 </strong><span style="font-family: "Times New Roman", serif;"><strong>(dest_cpu </strong></span></span><span style="color: red;"><strong>不等於 </strong><span style="font-family: "Times New Roman", serif;"><strong>smp_processor_id()</strong></span></span><span style="color: red;"><strong>時</strong><span style="font-family: "Times New Roman", serif;"><strong>).</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如<span style="font-family: "Times New Roman", serif;">,</span>當使用者執行一個新的程式<span style="font-family: "Times New Roman", serif;">,</span>就會透過函式<span style="font-family: "Times New Roman", serif;">do_execve (in fs/exec.c)</span>開啟該執行檔<span style="font-family: "Times New Roman", serif;">,</span>並呼叫函式<span style="font-family: "Times New Roman", serif;">sched_exec (in kernel/sched.c) </span>在新產生的<span style="font-family: "Times New Roman", serif;">Task</span>行程中執行<span style="font-family: "Times New Roman", serif;">“p->sched_class->select_task_rq”,</span>用以確認這個新產生的<span style="font-family: "Times New Roman", serif;">Task</span>要被排程的目標處理器<span style="font-family: "Times New Roman", serif;">,</span>是否跟目前所在的處理器一致<span style="font-family: "Times New Roman", serif;">,</span>那是那就返回繼續執行<span style="font-family: "Times New Roman", serif;">,</span>若非<span style="font-family: "Times New Roman", serif;">,</span>就會執行<span style="font-family: "Times New Roman", serif;">“stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);”</span>透過函式<span style="font-family: "Times New Roman", serif;">stop_one_cpu,</span>讓<span style="font-family: "Times New Roman", serif;">migration Kernel Thread</span>執行函式<span style="font-family: "Times New Roman", serif;">migration_cpu_stop</span>來進行<span style="font-family: "Times New Roman", serif;">Task</span>轉移的工作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>2,</strong></span></span><span style="color: red;"><strong>當</strong><span style="font-family: "Times New Roman", serif;"><strong>CPU</strong></span></span><span style="color: red;"><strong>的</strong><span style="font-family: "Times New Roman", serif;"><strong>Allowed Bitmask</strong></span></span><span style="color: red;"><strong>被修改</strong><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span></span><span style="color: red;"><strong>且該</strong><span style="font-family: "Times New Roman", serif;"><strong>Task</strong></span></span><span style="color: red;"><strong>正位於不被允許的處理器上</strong></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如<span style="font-family: "Times New Roman", serif;">,</span>當使用者透過<span style="font-family: "Times New Roman", serif;">set_cpus_allowed_ptr(in kernel/sched.c)</span>修改<span style="font-family: "Times New Roman", serif;">Task</span>的<span style="font-family: "Times New Roman", serif;">CPU Allowed Bitmask</span>時<span style="font-family: "Times New Roman", serif;">,</span>會執行 <span style="font-family: "Times New Roman", serif;">“if (cpumask_test_cpu(task_cpu(p), new_mask)) “</span>確認目前所在的處理器是否符合新的<span style="font-family: "Times New Roman", serif;">Bitmask</span>設定<span style="font-family: "Times New Roman", serif;">,</span>若所在的處理器並非允許執行的處理器<span style="font-family: "Times New Roman", serif;">,</span>就會執行<span style="font-family: "Times New Roman", serif;">“stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);”</span>透過函式<span style="font-family: "Times New Roman", serif;">stop_one_cpu,</span>讓<span style="font-family: "Times New Roman", serif;">migration Kernel Thread</span>執行函式<span style="font-family: "Times New Roman", serif;">migration_cpu_stop</span>來進行<span style="font-family: "Times New Roman", serif;">Task</span>轉移的工作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>3,</strong></span></span><span style="color: red;"><strong>當處理器沒有</strong><span style="font-family: "Times New Roman", serif;"><strong>Task</strong></span></span><span style="color: red;"><strong>運作時</strong><span style="font-family: "Times New Roman", serif;"><strong>(</strong></span></span><span style="color: red;"><strong>也就是處於</strong><span style="font-family: "Times New Roman", serif;"><strong>Idle</strong></span></span><span style="color: red;"><strong>的狀態</strong><span style="font-family: "Times New Roman", serif;"><strong>),</strong></span></span><span style="color: red;"><strong>由忙碌的處理器轉移</strong><span style="font-family: "Times New Roman", serif;"><strong>Task</strong></span></span><span style="color: red;"><strong>來執行</strong><span style="font-family: "Times New Roman", serif;"><strong>.</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如<span style="font-family: "Times New Roman", serif;">:</span>在排程函式<span style="font-family: "Times New Roman", serif;">schedule</span>中<span style="font-family: "Times New Roman", serif;">,</span>會透過<span style="font-family: "Times New Roman", serif;">“if (unlikely(!rq->nr_running)) “</span>確認目前該處理器是否處於沒有<span style="font-family: "Times New Roman", serif;">Task</span>執行的狀態<span style="font-family: "Times New Roman", serif;">,</span>若是就會嘗試把其它處理器上的<span style="font-family: "Times New Roman", serif;">Tasks</span>移到目前<span style="font-family: "Times New Roman", serif;">Idle</span>的處理器上執行<span style="font-family: "Times New Roman", serif;">. </span>首先<span style="font-family: "Times New Roman", serif;">,</span>會呼叫函式<span style="font-family: "Times New Roman", serif;">idle_balance (in kernel/sched_fair.c),</span>並確認<span style="font-family: "Times New Roman", serif;">sched_domain</span>的<span style="font-family: "Times New Roman", serif;">SD_BALANCE_NEWIDLE flag</span>是否成立<span style="font-family: "Times New Roman", serif;">,</span>若成立就會執行<span style="font-family: "Times New Roman", serif;">“pulled_task = load_balance(this_cpu, this_rq,sd, CPU_NEWLY_IDLE, &balance);”,</span>在函式<span style="font-family: "Times New Roman", serif;">load_balance (in kernel/sched_fair.c)</span>中<span style="font-family: "Times New Roman", serif;">,</span>會執行<span style="font-family: "Times New Roman", serif;">“stop_one_cpu_nowait(cpu_of(busiest), active_load_balance_cpu_stop, busiest, &busiest->active_balance_work);”</span>透過函式<span style="font-family: "Times New Roman", serif;">stop_one_cpu_nowait ,</span>讓<span style="font-family: "Times New Roman", serif;">migration Kernel Thread</span>執行函式<span style="font-family: "Times New Roman", serif;">active_load_balance_cpu_stop,</span>把<span style="font-family: "Times New Roman", serif;">Task</span>從目前最忙碌的處理器移到<span style="font-family: "Times New Roman", serif;">Idle</span>的處理器上<span style="font-family: "Times New Roman", serif;">. </span>有關處理器<span style="font-family: "Times New Roman", serif;">Task Balance</span>的動作<span style="font-family: "Times New Roman", serif;">,</span>值得討論的事項很多<span style="font-family: "Times New Roman", serif;">,</span>後續有機會再加以詳細說明<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>4,</strong></span></span><span style="color: red;"><strong>當處理器被關閉時 </strong><span style="font-family: "Times New Roman", serif;"><strong>(</strong></span></span><span style="color: red;"><strong>在有支援</strong><span style="font-family: "Times New Roman", serif;"><strong>HotPlug</strong></span></span><span style="color: red;"><strong>的環境下</strong><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span></span><span style="color: red;"><strong>進行</strong><span style="font-family: "Times New Roman", serif;"><strong>CPU Down)</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如<span style="font-family: "Times New Roman", serif;">:</span>進行<span style="font-family: "Times New Roman", serif;">CPU Down</span>時會透過函式<span style="font-family: "Times New Roman", serif;">cpu_down (in kernel/cpu.c)</span>進入 <span style="font-family: "Times New Roman", serif;">_cpu_down (in kernel/cpu.c) </span>執行<span style="font-family: "Times New Roman", serif;">“err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu));”,</span>透過函式 <span style="font-family: "Times New Roman", serif;">__stop_machine (in kernel/stop_machine.c)</span>呼叫<span style="font-family: "Times New Roman", serif;">stop_cpus (in kernel/stop_machine.c),</span>進入<span style="font-family: "Times New Roman", serif;">__stop_cpus (in kernel/stop_machine.c)</span>中<span style="font-family: "Times New Roman", serif;">,</span>執行函式<span style="font-family: "Times New Roman", serif;">cpu_stop_queue_work,</span>把工作透過<span style="font-family: "Times New Roman", serif;">list_add_tail(&work->list, &stopper->works); </span>放到<span style="font-family: "Times New Roman", serif;">stopper->works Queue</span>中<span style="font-family: "Times New Roman", serif;">,</span>讓<span style="font-family: "Times New Roman", serif;">migration Kernel Thread</span>執行函式<span style="font-family: "Times New Roman", serif;">take_cpu_down (in kernel/cpu.c)</span>完成<span style="font-family: "Times New Roman", serif;">CPU Down</span>的流程<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
上述四個條件<span style="font-family: "Times New Roman", serif;">,</span>是在目前<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>下<span style="font-family: "Times New Roman", serif;">,</span>會透過 <span style="font-family: "Times New Roman", serif;">migration Kernel Thread</span>執行的情況<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在啟動過程中<span style="font-family: "Times New Roman", serif;">,</span>會呼叫函式<span style="font-family: "Times New Roman", serif;">cpu_stop_init,</span>並以啟動的處理器作為<span style="font-family: "Times New Roman", serif;">Boot CPU</span>來呼叫函式<span style="font-family: "Times New Roman", serif;">cpu_stop_cpu_callback,</span>執行<span style="font-family: "Times New Roman", serif;">CPU_UP_PREPARE</span>的動作<span style="font-family: "Times New Roman", serif;">,</span>會以函式<span style="font-family: "Times New Roman", serif;">cpu_stopper_thread</span>做為<span style="font-family: "Times New Roman", serif;">migration Kernel Thread</span>的執行起點<span style="font-family: "Times New Roman", serif;">,</span>並以函式<span style="font-family: "Times New Roman", serif;">kthread_bind</span>設定該<span style="font-family: "Times New Roman", serif;">Thread</span>只能在目前產生該<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>的處理器上執行<span style="font-family: "Times New Roman", serif;">. </span>可以參考如下程式碼<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">unsigned long action, void *hcpu)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">{</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">unsigned int cpu = (unsigned long)hcpu;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct task_struct *p;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">switch (action & ~CPU_TASKS_FROZEN) {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">case </span><span style="color: #ff3333;"><span style="font-size: x-small;"><strong>CPU_UP_PREPARE</strong></span></span><span style="font-size: xx-small;">:</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">BUG_ON(stopper->thread || stopper->enabled ||</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">!list_empty(&stopper->works));</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #ff3333;"><span style="font-size: xx-small;"><strong>p = kthread_create_on_node(cpu_stopper_thread,</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #ff3333;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>stopper,</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #ff3333;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>cpu_to_node(cpu),</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #ff3333;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>“migration/%d”, cpu);</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">if (IS_ERR(p))</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">return notifier_from_errno(PTR_ERR(p));</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">get_task_struct(p);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kthread_bind(p, cpu);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sched_set_stop_task(cpu, p);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">stopper->thread = p;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">break;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.…..</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">migration Kernel Thread</span>會在<span style="font-family: "Times New Roman", serif;">CPU_UP_PREPARE</span>事件中產生<span style="font-family: "Times New Roman", serif;">,</span>並在<span style="font-family: "Times New Roman", serif;">CPU_ONLINE</span>事件被<span style="font-family: "Times New Roman", serif;">WakeUp</span>與設定<span style="font-family: "Times New Roman", serif;">“stopper->enabled = true;”.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在有支援<span style="font-family: "Times New Roman", serif;">CPU HotPlug</span>的環境中<span style="font-family: "Times New Roman", serif;">,</span>會有額外的<span style="font-family: "Times New Roman", serif;">CPU_UP_CANCELED</span>與<span style="font-family: "Times New Roman", serif;">CPU_POST_DEAD</span>事件<span style="font-family: "Times New Roman", serif;">,</span>會在透過函式<span style="font-family: "Times New Roman", serif;">kthread_stop</span>把<span style="font-family: "Times New Roman", serif;">migration Kernel Thread</span>結束<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在函式<span style="font-family: "Times New Roman", serif;">cpu_stopper_thread</span>中<span style="font-family: "Times New Roman", serif;">,</span>就會進入一個<span style="font-family: "Times New Roman", serif;">goto</span>的迴圈中<span style="font-family: "Times New Roman", serif;">,</span>確認<span style="font-family: "Times New Roman", serif;">stopper->works Queue</span>中是否有被指派的工作<span style="font-family: "Times New Roman", serif;">,</span>若有就會執行該工作對應的<span style="font-family: "Times New Roman", serif;">Callback</span>函式<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="94"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="536"><span style="font-size: x-small;">其他常見的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Kernel Thread</span></span><span style="font-size: x-small;">還包括</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">suspend,cqueue,aio,mtdblockd,hid_compat,rpciod,mmcqd….etc,</span></span><span style="font-size: x-small;">就不在這多做介紹</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">有興趣的開發者請自行參閱</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Linux Kernel Source Code.</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>結語</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文基本上以 <span style="font-family: "Times New Roman", serif;">kthreadd Task</span>為起點<span style="font-family: "Times New Roman", serif;">,</span>探討了一部分以此為基礎的核心模組<span style="font-family: "Times New Roman", serif;">,</span>然而由於涉及的領域很廣泛<span style="font-family: "Times New Roman", serif;">,</span>筆者主要以自己認為值得加以說明的模組進行介紹<span style="font-family: "Times New Roman", serif;">,</span>對核心解析有熱情的開發者<span style="font-family: "Times New Roman", serif;">,</span>建議可以自行進一步的<span style="font-family: "Times New Roman", serif;">Hacking.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>啟動流程的介紹<span style="font-family: "Times New Roman", serif;">,</span>就以本文告結<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-81798059736774422552017-06-03T17:09:00.002-07:002017-06-03T17:09:29.684-07:00Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(3) Linux 多核心啟動流程從rest_init到kernel_init與CPU Idle/HotPlug機制<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(3) Linux 多核心啟動流程從rest_init到kernel_init與CPU Idle/HotPlug機制</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(3) Linux 多核心啟動流程從rest_init到kernel_init與CPU Idle/HotPlug機制</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
hlchou@mail2000.com.tw</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
by loda.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
承襲之前的內容,本文會先把resr_init到kernel_init的流程做一個說明. 並針對Secondary處理器Booting,CPU Idle省電機制與CPU Up/Down HotPlug機制做介紹. 而屬於核心 Kthreadd機制,會放到下次的文章中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel針對CPU Idle與對應的省電機制,已經有滿不錯的框架,只要處理器平台開發者,根據自己的處理器架構,Power Group與對應的周邊適配進來,就可以達到省電最佳化的效益. 尤其,在多核心SMP架構上,Idle的省電機制在Linux Kernel中待改善的部分還非常多,這也是因為每個ARM SMP架構與周邊都會因為平台提供者的設計差異,而不容易標準化(畢竟這不是一家處理器業者獨大的市場). 要達到SMP多核心最佳的省電效益,就必須在基於對核心流程有清楚掌握下,針對要優化的平台來做調整,讓系統可以有更多的機會關閉對應的周邊供電與Clock,才有機會達到最佳化的省電效益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android除了TV產品外,多數的應用都是屬於移動裝置,而這些裝置對於省電需求,是非常殷切的. 以目前的平板電腦來說,不同的系統廠商採用同一個雙核心的晶片,最終所設計的產品,在待機時間上,兩者就可以有數倍的差距(mmm,商品名稱就別提了..@_@),其中很大的差異就是對於所採用平台的掌握度是不是足夠高,以及對於系統軟體的投注程度.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於筆者時間受限,本系列文章會分次刊登,還請見諒.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>rest_init</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這函式是Kernel初始化的最後一棒,負責的Bootstrap處理器,也會在這之後進入CPU Idle狀態,並讓系統行程Scheduling正常運作,也是我們了解Kernel時,值得清楚掌握的部份.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">rest_init 流程</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">rcu_scheduler_starting</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">實作在檔案kernel/rcutree.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
啟動Read-Copy Update,會呼叫num_online_cpus確認目前只有bootstrap處理器在運作,以及呼叫nr_context_switches確認在啟動RCU前,沒有進行過Contex-Switch,最後就是設定rcu_scheduler_active=1啟動RCU機制.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
RCU在多核心架構下,不同的行程要讀取同一筆資料內容/結構,可以提供高效率的同步與正確性.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在這之後就可以使用 rcu_read_lock/rcu_read_unlock了.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">產生Kernel Thread<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kernel_init</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">Kernel Thread函式 kernel_init實作在檔案init/main.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init Task PID=1,是核心第一個產生的Task.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
產生後,會停在函式呼叫wait_for_completion中,等待kthreadd_done Signal,以便往後繼續執行下去.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">產生Kernel Thread<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kthreadd</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">Kernel Thread函式 kthreadd實作在檔案kernel/kthread.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kthreadd Task PID=2,是核心第二個產生的Task.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">find_task_by_pid_ns</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">實作在檔案kernel/pid.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
呼叫函式find_task_by_pid_ns,並帶入參數 kthreadd的PID 2與PID NameSpace (struct pid_namespace init_pid_ns)取回PID 2的Task Struct.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">complete</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">實作在檔案kernel/sched.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會送出kthreadd_done Signal,讓 kernel_init(也就是 init task)可以往後繼續執行.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">init_idle_bootup_task</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">實作在檔案kernel/sched.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
設定目前啟動的Task為IDLE Task. (idle->sched_class = &idle_sched_class), 而struct sched_class idle_sched_class的宣告在檔案kernel/sched_idletask.c中.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Linux下IDLE Task並不佔PID(也可以把它當作是PID 0),每個處理器都會有這樣的IDLE Task,用來在沒有行程排成時,讓處理器掉入執行的.而最基礎的省電機制,也可透過IDLE Task來進行. (包括讓系統可以關閉必要的周邊電源與Clock Gating).</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">schedule();</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">實作在檔案kernel/sched.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//preempt_enable_no_resched/preempt_disable();</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
啟動Linux Kernel Process的排成Context-Switch機制.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">cpu_idle();</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="476">實作在檔案arch/arm/kernel/process.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這是處理器IDLE Task的主函式,我們會在稍後進一步說明,走到這,屬於Booting到IDLE Task的流程就算是初步結束了.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>kernel_init</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
實作在檔案 init/main.c中,這是Linux Kernel產生的第一個Tasks,也是User Mode起點init Task的產生者,所有User Space的初始化工作,包括Shell與相關的Script執行,都必須仰賴init Task,簡要說明如下</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">kernel_init<br />初始化函式的流程</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">wait_for_completion</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案kernel/sched.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會呼叫函式wait_for_completion,等待Kernel Thread kthreadd (PID=2)產生完畢.</div>
</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="648">init can run on any cpu</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">set_cpus_allowed_ptr</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案kernel/sched.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過這函式可以設定CPU bitmask,限定Task只能在特定的處理器上運作.而在init中,會設定為cpu_all_mask (= to_cpumask(cpu_all_bits)),<br />也就是 init Task可以在所有處理器上運作.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">cad_pid = task_pid(current);</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">呼叫task_pid (以inline實作在檔案include/linux/sched.h中),設定目前current的init Task PID給cad_pid<br />(也就是要用來接收”ctrl-alt-del” Reboot Signal的Process ID, 如果設定C_A_D=1,就表示可以處理來自”ctrl-alt-del”的動作.).<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後會呼叫函式ctrl_alt_del (in kernel/sys.c),並確認C_A_D是否為1,以便執行kernel_restart流程.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">smp_prepare_cpus</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案arch/arm/kernel/smp.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
呼叫函式smp_prepare_cpus時,會以全域變數setup_max_cpus為函式參數max_cpus,用以表示在編譯核心時,設定支援的最大CPU數量.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先,會透過函式num_possible_cpus(=cpumask_weight(cpu_possible_mask) ,in include/linux/cpumask.h)取得目前系統存在的處理器數量,<br />並呼叫函式smp_store_cpu_info,把透過calibrate_delay計算的loops_per_jiffy存到目前處理器的cpu_info (宣告為struct cpuinfo_arm *)中.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而Kernel中的全域變數setup_max_cpus初始值為NR_CPUS (參考檔案include/linux/threads.h 會以CONFIG_NR_CPUS 為值),如果編譯時設定的<br />處理器個數大於運作時取得的處理器個數(if (max_cpus > ncores) ),會以運作時偵測到的處理器個數為主.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
呼叫函式percpu_timer_setup,設定目前處理器的Local Timer.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
呼叫函式platform_smp_prepare_cpus (in arch/arm/mach-tegra/platsmp.c),依據max_cpus結果,透過函式set_cpu_present (in kernel/cpu.c),<br />設定這些處理器為present true.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">do_pre_smp_initcalls</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案init/main.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會透過函式do_one_initcall,執行介於Symbol __initcall_start與__early_initcall_end之間的函式呼叫,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為arch/arm/kernel/vmlinux.lds中的Symbol區間內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__initcall_start = .; *(.initcallearly.init) __early_initcall_end = .;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以筆者編譯的結果來說,會執行有透過early_initcall 註冊的函式,例如</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
spawn_ksoftirqd (in kernel/softirq.c),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_workqueues (in kernel/workqueue.c),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_call_single_data (in kernel/smp.c),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_stop_init (in kernel/stop_machine.c),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
….etc</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">smp_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案kernel/smp.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這函式主要是由Bootstrap處理器,進行Active多核心架構下其它的處理器.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果發生Online的處理器個數(from num_online_cpus)超過在核心編譯時,所設定的最大處理器個數 setup_max_cpus (from NR_CPUS),就會終止流程.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果該處理器目前屬於Present (也就是存在系統中),但尚未是Online的狀態,就會呼叫函式cpu_up(in kernel/cpu.c)來啟動該處理器.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">sched_init_smp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案kernel/sched.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,呼叫get_online_cpus,如果目前CPU Hotplug Active Write行程是自己,就直接返回.反之就把 cpu_hotplug.refcount加1 (表示多一個Reader)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,取得Mutex Lock “sched_domains_mutex”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,呼叫arch_init_sched_domains,設定scheduler domains與groups,參考Linux Documentation/scheduler/sched-domains.txt文件,一個<br />Scheduling Domain會包含一個或多個CPU Groups,排程的Load-Balance就會根據Domain中的Groups來做調整.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,釋放Mutex Lock “sched_domains_mutex”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,呼叫put_online_cpus,如果目前CPU Hotplug Active Writer行程是自己,就直接返回.反之就把 cpu_hotplug.refcount減1,如果 cpu_hotplug.refcount減到為0,表示沒有其他Reader,此時如果有CPU Hotplug Active Writer行程在等待,就會透過wake_up_process喚醒該行程,<br />以便讓等待中的Writer可以被執行下去.(也可以參考_cpu_up中對於函式cpu_hotplug_begin的說明).</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,註冊CPU Notifier cpuset_cpu_active/cpuset_cpu_inactive/update_runtime</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,呼叫set_cpus_allowed_ptr,透過這函式可以設定CPU bitmask,限定Task只能在特定的處理器上運作.在這會用參數”non_isolated_cpus”,也就是會把<br />init指定給non-isolated CPU. Linux Kernel可以在啟動時,透過Boot Parameters “isolcpus=“指定CPU編號或是範圍,讓這些處理器不被包含<br />在Linux Kernel SMP balancing/scheduling算法內,可以在啟動後指派給特定的Task運作.而不在 “isolcpus=“ 指定範圍內的處理器就算是non-isolated CPU.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,呼叫sched_init_granularity,透過函式update_sysctl,讓sysctl_sched_min_granularity=normalized_sysctl_sched_min_granularity,sysctl_sched_latency=normalized_sysctl_sched_latency,<br />sysctl_sched_wakeup_granularity=normalized_sysctl_sched_wakeup_granularity.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">do_basic_setup</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案init/main.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,呼叫usermodehelper_init (in kernel/kmod.c),產生khelper workqueue.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫init_tmpfs (in mm/shmem.c),對VFS註冊Temp FileSystem.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,呼叫driver_init (in drivers/base/init.c),初始化Linux Kernel Driver System Model.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,呼叫init_irq_proc(in kernel/irq/proc.c),初始化 “/proc/irq”與其下的File Nodes.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,呼叫do_ctors (in init/main.c),執行位於Symbol __ctors_start 到 __ctors_end間屬於Section “.ctors” 的Constructor函式.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,透過函式do_initcalls,執行介於Symbol __early_initcall_end與__initcall_end之間的函式呼叫,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為arch/arm/kernel/vmlinux.lds中的Symbol區間內容,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__early_initcall_end = .; *(.initcall0.init) *(.initcall0s.init) *(.initcall1.init) *(.initcall1s.init) *(.initcall2.init) *(.initcall2s.init)<br />*(.initcall3.init) *(.initcall3s.init) *(.initcall4.init) *(.initcall4s.init) *(.initcall5.init) *(.initcall5s.init) *(.initcallrootfs.init)<br />*(.initcall6.init) *(.initcall6s.init) *(.initcall7.init) *(.initcall7s.init) __initcall_end = .;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以筆者編譯的結果來說,會執行有透過__initcall 註冊的函式,例如</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(0….added by pure_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_atomic64_lock</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(1….added by core_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ptrace_break_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
consistent_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
v6_userpage_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
alloc_frozen_cpus</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
sysctl_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ksysfs_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_jiffies_clocksource</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pm_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_zero_pfn</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fsnotify_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
filelock_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_script_binfmt</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
nit_elf_binfmt</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
random32_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(2….added by postcore_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
tegra_gpio_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
tegra_dma_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bdi_class_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
tty_class_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vtconsole_class_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
wakeup_sources_debugfs_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(3….added by arch_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
customize_machine</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
exceptions_init</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(4….added by subsys_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
topology_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
param_sysfs_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
default_bdi_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_bio4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fsnotify_notification_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
blk_settings_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
blk_ioc_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
blk_softirq_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
blk_iopoll_setup4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
genhd_device_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
misc_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
serio_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
input_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
hwmon_init4</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(5….added by fs_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_cpu_init5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dma_debug_do_init5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
alignment_init5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
clocksource_done_booting5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_pipe_fs5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
eventpoll_init5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
anon_inode_init5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
blk_scsi_ioctl_init5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
chr_dev_init5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
firmware_class_init5</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(rootfs….added by rootfs_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
default_rootfs</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(6….added by device_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
timer_init_sysfs6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
register_pmu_driver6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_execdomains_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ioresources_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
uid_cache_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_posix_timers6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_posix_cpu_timers6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
nsproxy_cache_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
timekeeping_init_ops6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_clocksource_sysfs6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_timer_list_procfs6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
futex_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kallsyms_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
user_namespaces_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pid_namespaces_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
utsname_sysctl_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_per_zone_wmark_min6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kswapd_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
setup_vmstat6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mm_sysfs_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_vmalloc_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
procswaps_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
slab_proc_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
slab_sysfs_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fcntl_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_filesystems_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fsnotify_mark_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
dnotify_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
inotify_user_setup6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
aio_setup6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_locks_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_cmdline_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_consoles_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_cpuinfo_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_devices_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_interrupts_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_loadavg_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_meminfo_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_stat_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_uptime_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_version_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_softirqs_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_kmsg_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_page_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_devpts_fs6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_ramfs_fs6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
proc_genhd_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bsg_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
noop_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
deadline_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cfq_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
percpu_counter_startup6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pty_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
rand_initialize6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
topology_sysfs_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fusb300_udc_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
serport_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mousedev_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
atkbd_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
psmouse_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
hid_init6</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(7….added by late_initcall….)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init_oops_id7</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printk_late_init7</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pm_qos_power_init7</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
max_swapfiles_check7</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
random32_reseed7</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
seqgen_init7</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">sys_open</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">透過sys_open以Read/Write模式開啟Console “/dev/console”,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於系統在此時沒有任何檔案開啟,這個返回一定是 “0”. (也就是對應到stdin).</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">sys_dup(0)</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案fs/fcntl.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
宣告為”SYSCALL_DEFINE1(dup, unsigned int, fildes)”,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在這會連續執行兩次sys_dup,複製兩個sys_open開啟/dev/console所產生的檔案描述0 (也就是會多生出兩個1與2),只是都對應到”/dev/console”,<br />我們在System V streams下的Standard Stream一般而言會有如下的對應</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0:Standard input (stdin)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1:Standard output (stdout)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2:Standard error (stderr)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(為方便大家參考,附上Wiki URL <a href="http://en.wikipedia.org/wiki/Standard_streams" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/Standard_streams</a> )</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">ramdisk_execute_command與prepare_namespace</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">1,如果ramdisk_execute_command為0,就設定ramdisk_execute_command = “/init”<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,如果sys_access確認檔案ramdisk_execute_command 失敗,就把ramdisk_execute_command 設定為0,然後呼叫prepare_namespace去<br />mount root FileSystem.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="199">init_post</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="449">實作在檔案kernel/main.c中<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,呼叫async_synchronize_full (in kernel/async.c),用以同步所有非同步函式呼叫的執行,在這函式中會等待List async_running與async_pending都<br />清空後,才會返回. Asynchronously called functions主要設計用來加速Linux Kernel開機的效率,避免在開機流程中等待硬體反應延遲,影響到開機完<br />成的時間.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫free_initmem (in arch/arm/mm/init.c),釋放Linux Kernel介於__init_begin到 __init_end屬於 init Section的程式碼與資料.並會把Page個數<br />加到變數totalram_pages中,作為後續Linux Kernel在配置記憶體時可以使用的Pages.<strong> (</strong><strong>在這也可把</strong><br /><strong>TCM</strong><strong>範圍</strong><strong>(__tcm_start</strong><strong>到</strong><strong>__tcm_end)</strong><br /><strong>釋放加入到總</strong><strong>Page</strong><strong>中</strong><strong>,</strong><strong>但</strong><br /><strong>TCM</strong><strong>比外部記憶體有效率</strong><strong>,</strong><strong>適合多媒體</strong><strong>,</strong><br /><strong>中斷</strong><strong>,…etc</strong><strong>等對效能要求高的執行需求</strong><strong>,</strong><strong>放到總</strong><br /><strong>Page</strong><strong>中</strong><strong>,</strong><strong>成為可供一般目的配置的記憶體範圍</strong><strong>,<br />mmm,</strong><strong>是有點浪費的</strong><strong>.)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,設定system_state 為 SYSTEM_RUNNING,與設定init Task的”SIGNAL_UNKILLABLE” Signal Bit. (</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,產生第一個User Space行程.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4.a,如果ramdisk_execute_command不為0,就執行該命令成為init User Process.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4.b,如果execute_command不為0,就執行該命令成為init User Process.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4.c,如果上述都不成立,就依序執行如下指令</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
run_init_process(“/sbin/init”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
run_init_process(“/etc/init”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
run_init_process(“/bin/init”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
run_init_process(“/bin/sh”);</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也就是說會試著從/sbin/init, /etc/init, /bin/init 與 /bin/sh依序執行嘗試執行第一個 init User Process.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,如果都找不到可以執行的 init Process,就會進入Kernel Panic.如下所示</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
panic(“No init found. Try passing init= option to kernel. ”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“See Linux Documentation/init.txt for guidance.”);</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關IDLE Task, init Task 與 kthreadd Task的啟動流程與關係,如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBYGToP8AIGV7MkBpvWWsGs4WzEFxuZlYoGeSME_ahfjX49bkdD4o8jzbzo6jns-eF3C_vWzfBB3uuySJZJUtqb8EbvGrLz27K5eLkuA8Ux4DWeyS5bvM1hJZD57luZ6b53X5KjpE0qsw/s1600/image002%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="607" data-original-width="737" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBYGToP8AIGV7MkBpvWWsGs4WzEFxuZlYoGeSME_ahfjX49bkdD4o8jzbzo6jns-eF3C_vWzfBB3uuySJZJUtqb8EbvGrLz27K5eLkuA8Ux4DWeyS5bvM1hJZD57luZ6b53X5KjpE0qsw/s1600/image002%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CPU Mask</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel針對多核心的需求,提供了對應處理器狀態的CPU Mask Bitmap,參考kernel/cpu.c中的實作,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關CPU狀態的CPU Mask會包含以下五種屬性</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(也可以參考Linux Documentation/cpu-hotplug.txt文件)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,cpu_all_bits: 用以表示目前透過NR_CPUS設定的處理器Bits,例如系統中有4個處理器此值初始化為0x0000000f,如果有兩個處理器此值初始化為0x00000003.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,cpu_possible_bits:這表示系統實際Run-Time時,存在的處理器個數(cpu_all_bits是編譯時期指定的最大處理器個數),在系統初始化的過程中,會根據偵測到的處理器數量透過函式set_cpu_possible設定哪些Bits要為1. (如果有兩個處理器就是0x00000003). (set_cpu_possible會再透過 cpumask_set_cpu或 cpumask_clear_cpu設定對應Bit的值).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,cpu_online_bits:用以表示哪個處理器目前是Online(也就是可以正常使用並參與排程的與處理中斷).當處理器進行 CPU Up/Down時,就會更改Online Bits的狀態.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,cpu_present_bits: 用以表示目前系統中Present的處理器個數,且並非所有屬於Present的處理器,目前都是Online可供系統排程與處理中斷的. 通常Present跟Possible的處理器個數會是相等的.在有支援處理器熱插拔的環境下,Possible跟Present的關係為 ”cpu_possible_map = cpu_present_map + additional_cpus”,也就是說Present是指系統非外部額外加入的處理器數量,而Possible則會包含Present與額外插入的處理器數量.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,cpu_active_bits:用以表示目前有哪些處於Online,且為Active的處理器可供scheduler 依據domains/groups進行排程配置.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
相關巨集的定義,可以在include/linux/types.h中,看到如下宣告</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define DECLARE_BITMAP(name,bits) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned long name[BITS_TO_LONGS(bits)]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
與在include/linux/bitmap.h中,如下的宣告</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define BITMAP_LAST_WORD_MASK(nbits) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
( \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
((nbits) % BITS_PER_LONG) ? \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
與在include/linux/cpumask.h中,如下的宣告</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#if NR_CPUS <= BITS_PER_LONG</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define CPU_BITS_ALL \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{ \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#else /* NR_CPUS > BITS_PER_LONG */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define CPU_BITS_ALL \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{ \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[0 … BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif /* NR_CPUS > BITS_PER_LONG */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以筆者所在的環境來說,NR_CPUS設定為4,則 cpu_all_bits為一個unsigned long (也就是4bytes)初始值為0x0000000f,其它cpu_possible_bits,cpu_online_bits,cpu_present_bits與cpu_active_bits長度為為一個unsigned long 初始值為0. NR_CPUS會在Config Linux Kernel被設定,用來表示目前所編譯的核心最大支援的處理器個數.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>多核心架構下</strong><strong>,</strong><strong>跟</strong><strong>CPU</strong><strong>個數與狀態有關的基礎函式</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
全域變數setup_max_cpus (=NR_CPUS)可取得編譯時設定的處理器個數,函式smp_processor_id 可取得目前的處理器ID.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
取得目前系統在對應狀況(Online,Possible,Present或Active)的處理器個數</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define num_online_cpus() cpumask_weight(cpu_online_mask)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define num_possible_cpus() cpumask_weight(cpu_possible_mask)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define num_present_cpus() cpumask_weight(cpu_present_mask)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define num_active_cpus() cpumask_weight(cpu_active_mask)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
確認對應處理器目前的狀態 (Online,Possible,Present或Active).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>initcall</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel有提供initcall機制,讓每個核心模塊的設計者,可以在系統init初始的不同階段,執行對應的初始化動作.參考檔案include/linux/init.h,Linux Kernel有提供__define_initcall巨集,用以根據輸入的Level產生對應的 initcall Section,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define __define_initcall(level,fn,id) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static initcall_t __initcall_##fn##id __used \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
__attribute__((__section__(“.initcall” level “.init”))) = fn</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果使用者希望在初始SMP前(也就是呼叫smp_init前), 有要執行的函式,就可以透過early_initcall (會把指定的函式放到 Level early中,也就是Section .initcallearly.init),如此在執行到函式do_pre_smp_initcalls時,就會執行Section .initcallearly.init裡被註冊的函式呼叫,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define early_initcall(fn) __define_initcall(“early”,fn,early)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以筆者所編譯的ARM Tegra環境來說,在init執行到尾聲時,會呼叫do_initcalls,進行執行使用者模式init前的最後核心裝置與檔案系統…等的initcall呼叫,在筆者的環境中主要會產生以下的Level “0”,“1”,”2”,”3”,”4”,”5”,”rootfs”,”6”與 ”7”,並且會對應到如下的Section “.initcall0.init”,”.initcall1.init”,”.initcall2.init”,”.initcall3.init”,”.initcall4.init”,”.initcall5.init”,”.initcallrootfs.init”,”.initcall6.init”, 與”.initcall7.init” .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對應的宣告如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define pure_initcall(fn) __define_initcall(“0″,fn,0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define core_initcall(fn) __define_initcall(“1″,fn,1)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define postcore_initcall(fn) __define_initcall(“2″,fn,2)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define arch_initcall(fn) __define_initcall(“3″,fn,3)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define subsys_initcall(fn) __define_initcall(“4″,fn,4)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define fs_initcall(fn) __define_initcall(“5″,fn,5)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define rootfs_initcall(fn) __define_initcall(“rootfs”,fn,rootfs)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define device_initcall(fn) __define_initcall(“6″,fn,6)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define late_initcall(fn) __define_initcall(“7″,fn,7)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在實際的程式碼中,可以看到例如在檔案kernel/softirq.c中,函式static __init int spawn_ksoftirqd(void),會執行 early_initcall(spawn_ksoftirqd) 把函式spawn_ksoftirqd放到Section “.initcallearly.init”.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或像是在檔案arch/arm/kernel/setup.c中,函式static int __init topology_init(void) 後會宣告subsys_initcall(topology_init)把函式 topology_init放到Section ”.initcall4.init”. ( topology_init會把系統中每個處理器 cpuinfo->cpu.hotpluggable設定為1,並呼叫register_cpu )</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在檔案kernel/posix-timers.c中,函式static __init int init_posix_timers(void)會執行__initcall(init_posix_timers)把函式 init_posix_timers放到 Section ”.initcall6.init” (實際上__initcall 會宣告為device_initcall).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以及在檔案drivers/char/random.c中,函式static __init int seqgen_init(void)回執行late_initcall(seqgen_init)把函式 seqgen_init放到Section “.initcall7.init”.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>與平台相關的函式</strong><strong>boot_secondary</strong><strong>與</strong><strong>Secondary</strong><strong>處理器啟動流程</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要了解不同處理器平台(例如Nvidia Tegra (in arch/arm/mach-tegra/platsmp.c), TI OMAP (in arch/arm/mach-omap2/omap-smp.c)或Qualcomm MSM (in arch/arm/mach-msm/platsmp.c)對多核心啟動的實作差異,從這個函式就可以揭露出概略的框架,例如</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="141">處理器</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="503">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="141">NVIDIA Tegra</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="503">參考arch/arm/<strong>mach-tegra/platsmp.c</strong><strong>中的實作</strong><strong>,</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,透過virt_to_phys(tegra_secondary_startup)取得函式tegra_secondary_startup的Physical Adress</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,讀取並暫存HW Register EVP_CPU_RESET_VECTOR 的值,並把把函式tegra_secondary_startup的Physical Address寫入HW Register EVP_CPU_RESET_VECTOR</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,致能Secondary處理器的Clock</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,執行smp_wmb (=barrier),透過Memory Barrier執行ARM dmb sy指令(Data Memory Barrier)與Flush Cache,讓處理器重新去外部記憶體讀取資料到Register與Cache中.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,設定HW Register TEGRA_FLOW_CTRL_BASE的值(Unhalt the Online CPU),讓處理器可以開始運作 (透過 Flag Register去執行函式tegra_secondary_startup與後續流程)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,HW Register EVP_CPU_RESET_VECTOR的值,如果跟原本寫入的不同 (也就是說不等於函式tegra_secondary_startup的Physical Address),就表示Secondary處理器順利被啟動了.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,還原原本 HW Register EVP_CPU_RESET_VECTOR的值.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
至此,就完成Tegra雙核心架構下,由Bootstrap處理器把SMP的Secondary處理器帶起來的動作.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGek-PKdPvC_q30TeHu8grrQsAP4wARea2tIkWDRmhNdltzIHFizphaggZxjKDncf6mo7aItfBQ5o5tqvgOJXfdEPBdpD5dCjPIbjTu6Bmnk6snqYg4vclkD6ld-B0ptPlUIaVceEPrXo/s1600/image004%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="586" data-original-width="338" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGek-PKdPvC_q30TeHu8grrQsAP4wARea2tIkWDRmhNdltzIHFizphaggZxjKDncf6mo7aItfBQ5o5tqvgOJXfdEPBdpD5dCjPIbjTu6Bmnk6snqYg4vclkD6ld-B0ptPlUIaVceEPrXo/s1600/image004%255B1%255D.png" /></a></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考資訊:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define EVP_CPU_RESET_VECTOR \</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
TEGRA_EXCEPTION_VECTORS_BASE =0x6000F000</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="141">Qualcomm MSM</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="503">參考 arch/arm/mach-msm/platsmp.c中的實作,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,呼叫prepare_cold_cpu,透過函式scm_set_boot_addr利用Qualcomm的SCM(Secure Channel Manager)介面,把函式msm_secondary_startup的Physical Address傳給Online處理器.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,把全域變數pen_release設定為Secondary處理器CPU ID(沒特別的意義,只是要在後面利用確保這個值不為-1來確認Secondary處理器是不是被啟動了).</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Flush DCache 與全域變數pen_release的在Layer2 Cache中的內容.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,呼叫smp_cross_call,觸發Software Interrupt給Secondary處理器,讓Secondary處理器開始啟動流程.(透過 Flag Register去執行函式msm_secondary_startup與後續流程)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,接下來會確任全域變數pen_release是否為-1,若是就表示Secondary處理器順利被啟動了.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="141">TI OMAP</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="503">參考 arch/arm/mach-omap2/omap-smp.c中的實作,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, 雙核心的OMAP Secondary處理器,會在啟動後進入函式omap_secondary_startup中(in arch/arm/mach-omap2/omap-headsmp.S),並透過smc (Secure Monitor Call)讀取AuxCoreBoot0的內容. (TI OMAP有支援 TrustZone Security Extensions,所以可以使用SMC指令,進入Secure Mode.)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,直到Bootstrap處理器透過omap_modify_auxcoreboot0(0x200, 0xfffffdff);更新AuxCoreBoot0內容.讓函式omap_secondary_startup離開hold的迴圈.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Bootstrap處理器會透過smp_cross_call(cpumask_of(cpu), 1)觸發IPI (Inter-Processor Interrupt)給Secondary處理器.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,此時Secondary處理器往後進入函式secondary_startup中執行後續流程.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以上,筆者把目前常見的Dual-Core平台,如何把Secondary處理器帶起的機制做一個簡要說明,我們可以看到每一個方案的作法都有些許的差異,但其實主要還是在於Reset/Halt機制或是透過 Flag Register/Loop(ex,WFI-Loop)的作法. 在平台的實現上,我們可以根據自己的處理器方案,設計適合啟動流程. ㄟ…..當然,並不是每個平台都會有TrustZone的 (Linux Kernel也是在沒有Enable這個Feature下執行),所以,SMC的機制,也就不是每個平台實現時,需要考慮的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>cpu_up</strong><strong>與</strong><strong>cpu_down</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel支援CPU hotplug機制,並可透過全域變數cpu_hotplug_disabled決定處理器Hot Plug機制的致能與否.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考檔案 kernel/cpu.c,如果全域變數cpu_hotplug_disabled被設定為1,cpu_up與cpu_down機制就會失效(返回-EBUSY). 在實作上,可以呼叫函式enable_nonboot_cpus致能CPU Up/Down機制,或呼叫函式disable_nonboot_cpus關閉CPU Up/Down機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CPU Up呼叫流程為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_up (in kernel/cpu.c) -> _cpu_up (in kernel/cpu.c) → __cpu_up (in arch/arm/kernel/smp.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下簡述這三個流程的動作.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">CPU UP 流程</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="692">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">1, “cpu_up”<br />(in kernel/cpu.c)</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="692">1,呼叫cpu_possible確認目前要Online的處理器是否可被啟用.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫cpu_maps_update_begin 設定Mutex Lock “cpu_add_remove_lock”</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,確認cpu_hotplug_disabled是否有被設定 (也就是不允許動態的CPU Online動作)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,呼叫 <strong>_cpu_up(cpu, 0)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,呼叫cpu_maps_update_done解開Mutex Lock “cpu_add_remove_lock”</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">2, “_cpu_up”<br />(in kernel/cpu.c)</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="692">1,如果該CPU已經Online或是非Present的狀態,就返回錯誤<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫cpu_hotplug_begin,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2.a,設定Active Write為目前的Process (cpu_hotplug.active_writer = current),取得 Mutex Lock “cpu_hotplug.lock”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2.b,如果 cpu_hotplug.refcount為0,表示目前沒有其它Reader,因此,可以結束函式cpu_hotplug_begin,讓_cpu_up後續工作繼續</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2.c,反之,如果cpu_hotplug.不為0,就會把行程設定為TASK_UNINTERRUPTIBLE,並解開Mutex Lock “cpu_hotplug.lock”,觸發排程,讓其它的Reader把工作結束<br /><strong><span style="text-decoration-line: underline;">(</span></strong><strong><span style="text-decoration-line: underline;">必須讓</span></strong><strong><span style="text-decoration-line: underline;">Write</span></strong><strong><span style="text-decoration-line: underline;">取得</span></strong><strong><span style="text-decoration-line: underline;">Mutex Lock “cpu_hotplug.lock”</span></strong><strong><span style="text-decoration-line: underline;">以及</span></strong><strong><span style="text-decoration-line: underline;">cpu_hotplug.refcount</span></strong><strong><span style="text-decoration-line: underline;">為</span></strong><strong><span style="text-decoration-line: underline;">0,</span></strong><strong><span style="text-decoration-line: underline;">才能讓函式</span></strong><strong><span style="text-decoration-line: underline;">cpu_hotplug_begin</span></strong><strong><span style="text-decoration-line: underline;">結束</span></strong><strong><span style="text-decoration-line: underline;">).</span></strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,呼叫__cpu_notify,透過函式__raw_notifier_call_chain,通知CPU Chain中的處理器,目前正在進行Online動作的處理器狀態為”CPU_UP_PREPARE”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,呼叫 <strong>__cpu_up(cpu)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,呼叫cpu_notify,透過函式__raw_notifier_call_chain,通知CPU Chain中的處理器,目前完成Online動作的處理器狀態為”CPU_ONLINE”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,呼叫cpu_hotplug_done,設定Active Write為NULL (cpu_hotplug.active_writer = NULL),解開Mutex Lock “cpu_hotplug.lock”.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="154">3, “__cpu_up”<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(in arch/arm/kernel/smp.c)</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="692">1,呼叫per_cpu取得要Online處理器的cpuinfo_arm結構 (in arch/arm/include/asm/cpu.h),如下所示<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>struct cpuinfo_arm {</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>struct cpu cpu;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#ifdef CONFIG_SMP</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>struct task_struct *idle; //</strong><strong>會指向目前這個處理器的</strong><strong>IDLE Task.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>unsigned int loops_per_jiffy;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>#endif</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>};</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,如果目前處理器沒有指定Idle Task,就透過函式fork_idle (in kernel/fork.c)產生Idle Task後指定給這個處理器. 函式fork_idle會呼叫copy_process複製一個PID = init_struct_pid的行程,並執行函式init_idle_pids與init_idle把這Idle Task指定給要Online的處理器.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,反之,如果這處理器已經有Idle Task,就呼叫函式init_idle (in kernel/sched.c)指定Idle Task給目前進行Online的處理器.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,呼叫函式pgd_alloc (in arch/arm/mm/pgd.c),會以1MB TLB Settings (約需要16kbytes 記憶體),產生TLB Level 1的Page Table.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,如果PHYS_OFFSET != PAGE_OFFSET <strong>(PHYS_OFFSET</strong><strong>為</strong><strong>Kernel Image</strong><strong>在實體記憶體中的</strong><strong>Offset,PAGE_OFFSET</strong><strong>為</strong><strong>Kernel Image</strong><strong>在虛擬記憶體中的</strong><strong>Offset,</strong><strong>一般而言為</strong><strong>0x8000)</strong>,就會透過函式identity_mapping_add (in arch/arm/mm/idmap.c),把Linux Kernel Image 程式區段 (_stext 到_etext)與資料區段(_sdata到_edata)的記憶體分頁以1MB TLB與AP (Access Permission)為PMD_SECT_AP_WRITE (1 << 10) 屬性設定到TLB分頁中.有關記憶體分頁的屬性與對應的Bits如下圖所示,以現有程式碼的配置來說,對Linux Kernel 的程式與資料區段是特權等級Privileged permissions為Read/Write,而一般應用程式User permissions為No Access.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8Hf2cjj0UXF5V4u_Q_TM0JT-FRs3fJ__SOsjmfEWlgeKOl58CwrroPfgf49TJCXd3xsJCpwiC2FbZznOTw7AGv1clunwdDxdz_Z6Y_Lc50MKZOov_iUH_9Ia8MvDG9XLF9OBmDdXIUhk/s1600/image006%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="254" data-original-width="604" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8Hf2cjj0UXF5V4u_Q_TM0JT-FRs3fJ__SOsjmfEWlgeKOl58CwrroPfgf49TJCXd3xsJCpwiC2FbZznOTw7AGv1clunwdDxdz_Z6Y_Lc50MKZOov_iUH_9Ia8MvDG9XLF9OBmDdXIUhk/s1600/image006%255B1%255D.png" /></a></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
至此就完成對新增處理器的初步MMU記憶體分頁與安全性的配置動作.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,設定要Online處理器的Stack (secondary_data.stack)與Page Table(secondary_data.pgdir)位址到全域變數struct secondary_data.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,呼叫函式__cpuc_flush_dcache_area進行 DCache Flush (範圍是全域變數struct secondary_data在記憶體的起點與大小)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,呼叫函式outer_clean_range把Clean L2 Cache (範圍是全域變數struct secondary_data在記憶體的起點與大小)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9,透過函式<strong>boot</strong><strong>_secondary</strong> (in arch/arm/mach-tegra/platsmp.c)帶起Online處理器.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10,secondary_data.stack = NULL;與secondary_data.pgdir = 0;</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
11, 如果PHYS_OFFSET != PAGE_OFFSET,就會透過函式identity_mapping_del把之前配置的Linux Kernel Image 程式區段 (_stext 到_etext)與資料區段(_sdata到_edata)記憶體分頁刪除.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
12, 呼叫函式pgd_free釋放Page Table.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行完畢__cpu_up,就完成了新增處理器的流程.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGSXP22GGei3jD51WRxIsJVfTlwIj9tW1j-xRTUSXY5rnprBsooxRoBljtOXDePEoZGp6-_m54KOkHkgvnqFkeqtWiltG3fYFQfPteoSSe-g0t5IKrvmPyOhjPLPs3dN6mQkCwMr3iB-0/s1600/image008%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="599" data-original-width="814" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGSXP22GGei3jD51WRxIsJVfTlwIj9tW1j-xRTUSXY5rnprBsooxRoBljtOXDePEoZGp6-_m54KOkHkgvnqFkeqtWiltG3fYFQfPteoSSe-g0t5IKrvmPyOhjPLPs3dN6mQkCwMr3iB-0/s1600/image008%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CPU Down呼叫流程為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_down (in kernel/cpu.c) -> _cpu_down (in kernel/cpu.c) → __cpu_die (in arch/arm/kernel/smp.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下簡述這三個流程的動作.</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">CPU DOWN流程</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="409">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">1,”cpu_down”<br />(in kernel/cpu.c)</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="409">1,呼叫cpu_maps_update_begin 設定Mutex Lock “cpu_add_remove_lock”<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,確認cpu_hotplug_disabled是否有被設定</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,呼叫 <strong>_cpu_down(cpu, 0)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,呼叫cpu_maps_update_done解開Mutex Lock “cpu_add_remove_lock”</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">2,”_cpu_down”<br />(in kernel/cpu.c)</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="409">1,呼叫函式num_online_cpus,確認如果目前Online的處理器只有一個,會直接返回錯誤 (mmmm,如果這個也Down下去就沒有處理器可用了…)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫函式cpu_online,如果該CPU並非Online狀態,就返回錯誤</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,呼叫cpu_hotplug_begin,取得 Mutex Lock “cpu_hotplug.lock”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,呼叫__cpu_notify,透過函式__raw_notifier_call_chain,通知CPU Chain中的處理器,目前正在進行Online動作的處理器狀態為”CPU_DOWN_PREPARE”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,呼叫函式__stop_machine (in )</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5.a,透過函式set_state設定struct stop_machine_data smdata 中的state為STOPMACHINE_PREPARE</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5.b,透過函式stop_cpus,停止指定的處理器. 會在關閉Preemption的狀態下,透過cpu_stop_queue_work,讓要被停止的處理器執行函式take_cpu_down.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5.c,由於是由要被停止的處理器執行函式take_cpu_down,在這函式的實作中,會呼叫__cpu_disable(in arch/arm/kernel/smp.c),把自己Offline,Migrate IRQ給其他處理器,停止Local Timer,Flush Cache/TLB,透過cpumask_clear_cpu把自己從Memory Management CPU Mask中移除,最後透過cpu_notify通知自己處於CPU_DYING.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5.d,進入Callback函式migration_call中 (in kernel/sched.c),並透過函式migrate_tasks把要Offline處理器的Tasks轉移到其它處理器上. (在這之後,處理器就只剩下Idle Task.).</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,透過BUG_ON(cpu_online(cpu)),確認要停止的處理器,是否已經處於Offline的狀態. (若還是在Online狀態就會導致Kernel Panic)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,呼叫函式idle_cpu (in kernel/shced.c),確認要Offline處理器是否正在執行idle task.(前面的migrate_tasks已經把要Offline處理器的所有Tasks都轉到其它處理器上了).若該處理器不是正在執行Idle Task,就會呼叫 cpu_relax (對應的實作為ARM的Memory Barrier),直到確認要Offline的處理器是處於Idle Task中.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,呼叫 <strong>__cpu_die(cpu)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9,呼叫cpu_notify_nofail,通知完成Offline動作的處理器狀態為”CPU_DEAD”.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10,呼叫check_for_tasks,確認目前是否還有Tasks在被停止的處理器上,若有就會Printk出警告訊息…(ㄟ….就算有在這階段也來不及做啥了……@_@)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
11,呼叫cpu_hotplug_done,設定Active Write為NULL,解開Mutex Lock “cpu_hotplug.lock”.</div>
</td></tr>
<tr class="alt over"><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="235">3,”__cpu_die”<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(in arch/arm/kernel/smp.c)</div>
</td><td style="background: rgb(226, 226, 226); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="409">1,會執行函式wait_for_completion_timeout,等待函式cpu_die 透過函式 complete 設定“Completion”給 cpu_died物件,如果cpu_died物件有設定完成或是TimeOut就會繼續往後執行.有關cpu_die函式的執行,是在處理器初始化到最後時,會透過函式rest_init呼叫到函式cpu_idle (in arch/arm/kernel/process.c)中,由cpu_idle執行處理器的IDLE流程. 而在cpu_idle中,在有支援CPU HotPlug的組態下,會去確認處理器是否被Offiline,若是就會執行 cpu_die,如下所示<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef CONFIG_HOTPLUG_CPU</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (cpu_is_offline(smp_processor_id()))</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_die();</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫platform_cpu_kill (in arch/arm/mach-tegra/hotplug.c),以Tegra方案來說,這函式為空函式.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,而CPU Idle Task在執行cpu_die後,就會進入函式platform_cpu_die (in arch/arm/mach-tegra/hotplug.c),並透過platform_do_lowpower,讓處理器處於WFI Low Power的狀態,等待下一次的喚醒.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,若處理器重新被喚醒,就會執行函式secondary_start_kernel (in arch/arm/kernel/smp.c),重新執行初始化流程.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行完畢__cpu_die,就完成了卸載處理器的流程.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8LbHIc__UdEuQvCpHx4KTBm_jOVCnrx-XIwrvjlq3PitBCGippmyfP4ET0OSqrrxLuD6IL_1eK-kLPOwZ5ViD-rArS31uza3jDKdIVSlaWLsXaS6AYgC0V_foAp2n7oURm7oEGClSh6A/s1600/image010%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="601" data-original-width="810" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8LbHIc__UdEuQvCpHx4KTBm_jOVCnrx-XIwrvjlq3PitBCGippmyfP4ET0OSqrrxLuD6IL_1eK-kLPOwZ5ViD-rArS31uza3jDKdIVSlaWLsXaS6AYgC0V_foAp2n7oURm7oEGClSh6A/s1600/image010%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>cpu_idle</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
實作在檔案arch/arm/kernel/process.c中,當處理器沒有其它Task執行時,就會在這函式中運作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel支援 Tickless System (設定路徑在Kernel Features —>Tickless System (Dynamic Ticks)),如果有選擇這能力,會在.config中設定CONFIG_NO_HZ=y. 當處理器執行IDLE Task時,可以停止系統的Scheduling Tick,也就是說進入pm_idle時,可以減少Timer中斷觸發(例如HZ=100,每秒就有一百次Tick Timer中斷觸發),減少系統醒來的機會.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關CPU Idle的說明,也可以參考Linux Kernel文件”Documentation/scheduler/sched-arch.txt”,如下簡述 CPU Idle的行為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,Enable FIQ.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,進入 while(1) 的 Loop</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-1,呼叫tick_nohz_stop_sched_tick,停止Scheduling Tick,包括會透過get_next_timer_interrupt取得下一次Timer中斷,跟現在的時間計算Delta delta_jiffies,如果delta_jiffies過小(=1),也就是說下個Timer中斷很快就會被觸發,就會直接結束這函式. (間隔過短,關閉Scheduling Tick所產生的效益就降低了.),由於系統時間所依賴的jiffies就是透過Scheduling Tick更新,因此在這函式中也會針對暫停Scheduling Tick引起的時間差,預備修正的機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2,進入while (!need_resched()) Loop ,執行need_resched可以知道是否需要重新排程,或是要準備進入IDLE的省電機制中. Idle 流程不會Set或Clear 函式need_resched所參考的TIF_NEED_RESCHED,當Idle流程觸發排程時,才會Clear該狀態</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-1,如果目前的處理器已經被Offline,則呼叫cpu_die</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-2,Disable IRQ</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-3,如果hlt_counter不為0,就會Enable IRQ,執行cpu_relax. 如果有呼叫platform_suspend_ops中的 end 函式指標,就會呼叫enable_hlt,讓hlt_counter不為0,反之如果呼叫begin函式指標,就會透過disable_hlt,讓htl_counter減為0. (並非所有ARM方案都有設定Platform Suspend Operation的機制,例如TI OMAP有,而Nvidia Tegra則無).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-2-4,若hlt_counter為0,就會進入每個平台差異化的pm_idle實作,在這個函式指標中,會依據每個平台的實作不同,在系統初始化時,設定給不同的Power Management函式.例如:omap2_pm_idle,omap3_pm_idle或s5p64x0_idle,在這就可以根據每個平台的差異,優化跟平台有關的Power Saving機制,包括關閉PMU Power Group(LDO)或是停止PLL..等,讓系統可以進入更深度的省電模式. 執行完畢pm_idle後,就會Enable IRQ,往後繼續執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-3,呼叫tick_nohz_restart_sched_tick,恢復Scheduling Tick,並更新jiffies</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-4,執行preempt_enable_no_resched,致能Preemptive排程 (Call dec_preempt_count())</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-5,進行Kernel Scheduling</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2-6,執行preempt_disable,關閉Preemptive排程 (Call inc_preempt_count()),在cpu_idle中,除了要觸發排程外,多數的情況下Preemptive排程會被關閉,直到要重新觸發Linux Kernel排程才會致能Preemptive機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於上述的說明,筆者把CPU Idle主要的行為,用如下的圖示表示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjhIgsXPGixpPYYhnm7kY3ggGWB2x6WKamyFZn_jmOvQPFuTF46A3sfdDc8nHsFYsdIEC2WcIDEdNkV7gesYNN_pUV7v8KJfjxzvXEguGAxT4Pqx0sL4flOE_aA2Pi4yXm5Tt-TIk4jxY/s1600/image012%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="673" data-original-width="747" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjhIgsXPGixpPYYhnm7kY3ggGWB2x6WKamyFZn_jmOvQPFuTF46A3sfdDc8nHsFYsdIEC2WcIDEdNkV7gesYNN_pUV7v8KJfjxzvXEguGAxT4Pqx0sL4flOE_aA2Pi4yXm5Tt-TIk4jxY/s1600/image012%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
希望透過本文的介紹,各位可以對Linux Kernel與Idle機制有清楚的藍圖,進而在ARM MPCore產品,有更好的掌握度.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com1tag:blogger.com,1999:blog-1668810802505961314.post-5796942088770239052017-06-03T09:01:00.001-07:002017-06-03T09:01:20.231-07:00Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(2) Linux Kernel SMP zImage到start_kernel流程.<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(2) Linux Kernel SMP zImage到start_kernel流程.</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(2) Linux Kernel SMP zImage到start_kernel流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
hlchou@mail2000.com.tw</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
by loda.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Mmmmmm,必須承認,我把這篇文章寫的有點囉嗦,以前在Linux Kernel上的工作,沒有留下太多的筆記,抽象的概念,容易隨著下一個產品或是技術的開發,成為過往記憶的一部分,這次重新整理,希望以後回來看時,可以很快Pick-up所有的細節,所以在一些枝微末節上,會比較嘮叨.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也因此,如果你原本就對ARM與Linux Kernel原始碼有一定的基礎,可能讀起本文來會比較輕鬆些. 若是有些部分,筆者探究的太過細節,還請各位見諒.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel對於SMP的支援有三種組合,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,不支援SMP的Linux Kernel</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,支援SMP的Linux Kernel <strong>(</strong><strong>關閉</strong><strong>SMP</strong><strong>對於單核心</strong><strong>UniProcessor</strong><strong>的支援</strong><strong>,SMP_ON_UP=n)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,支援SMP/UP的Linux Kernel <strong>(</strong><strong>開啟</strong><strong>SMP</strong><strong>對於單核心</strong><strong>UniProcessor</strong><strong>的支援</strong><strong>,SMP_ON_UP=y)</strong>,並在啟動時,如果偵測到為UniProcessor時,會自我修正不能在non-SMP運作的指令.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前SMP_ON_UP選項只在ARM處理器上有.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其實,整個Linux Kernel中包括PageSet,Process ID Map與相關的資料結構,都會參考目前系統中的處理器個數,來做出對應的配置,也就是說Linux Kernel對於支援多核心的架構,已經是相當的內化(骨子裡…就是會考慮到多核心的情況.),並蘊含在許多核心模組的設計上. 也因此,在整理本文的過程中,收獲最大的也是筆者自己對於SMP架構與Linux Kernel模組的藍圖. 並希望對閱讀本文的人也能有所助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文主要從zImage開始到start_kernel完畢(rest_init除外),並以Tegra平台為主要參考,由於並非所有函式都在筆者平台上被參考到,在說明中也會略過,只選擇在這平台上比較重要的部份.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於筆者時間受限,本系列文章會分次刊登,還請見諒.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Linux Kernel Image</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
依據開發的需求,Linux Kernel Image可以編譯為 zImage (Compressed kernel image),Image (Uncompressed kernel image),xipImage(XIP(eXecution In Place) kernel image),uImage(U-Boot wrapped zImage)與 bootpImage( Combined zImage and initial RAM disk).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若對Linux Kernel編譯過程有興趣,可在編譯時加上 KBUILD_VERBOSE=1,讓quiet參數為空白,可把編譯過程吐到Console中,便於觀察.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>不只是</strong><strong>ARMv32,</strong><strong>還支援</strong><strong>Thumb2</strong><strong>的</strong><strong> </strong><strong>Linux Kernel Image</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果所選擇的處理器是ARMv7 (也就是Cortex的架構),可以透過勾選Experimental程式碼的選項,就可把Linux Kernel以Thumb2的方式進行編譯.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關ARMv32與Thumb2效能的比較可以參考這篇在ARM工作的Richard Phelan所寫的文章Improving ARM Code Density and Performance (http://www.cs.uiuc.edu/class/fa05/cs433ug/PROCESSORS/Thumb2.pdf), 以C Code實作同樣的功能來說,編譯為Thumb2最高可以達到98%的ARM指令及效能,程式碼本身所需的記憶體空間只佔原本ARM程式碼的74%. 對記憶體受限的嵌入式裝置,以Thumb2 16/32 bits混合的程式碼可以得到較佳的 Performance/Code Size的C/P值.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在選擇Linux Kernel選單時,只要進行如下勾選即可,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
General setup —>Prompt for development and/or incomplete code/drivers</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
與</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Kernel Features —>Compile the kernel in Thumb-2 mode</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前筆者並未驗證過這部份的代碼,僅作為有興趣的開發者參考資訊.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Linux Kernel</strong><strong>編譯時所產生的</strong><strong>Relocatable Object File.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當一個編譯系統比較龐大時,如果是一次要Link大量的.o或.a檔時,要解決這些Symbol Resolve會需要的記憶體與運算成本,也會對應的提高,Linux Kernel有使用GCC relocatable output的機制,讓個別模組可以先進行 Symbol Resolve,節省最後Kernel Image產生的運算資源. 簡要說明如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, 編譯過程中,會透過arm-eabi-ld (GCC Linker) 搭配 “-r” 產生”relocatable output”,例如:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-ld -EL -r -o drivers/tty/vt/built-in.o drivers/tty/vt/vt_ioctl.o drivers/tty/vt/vc_screen.o drivers/tty/vt/selection.o drivers/tty/vt/keyboard.o drivers/tty/vt/consolemap.o drivers/tty/vt/consolemap_deftbl.o drivers/tty/vt/vt.o drivers/tty/vt/defkeymap.o</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會把 drivers/tty/vt下的.o檔案,產生出一個在內部已經做過Symbol Resolved動作的集合Object檔案 built-in.o,透過objdump我們先檢視在目錄下的vt.o檔案中呼叫外部函式vt_ioctl,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-objdump -t vt.o|grep “vt_ioctl”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00000000 *UND* 00000000 vt_ioctl</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於該函式的實作不在vt.c中,因此在編譯後,.o檔案中的Symbol會被標示為 “Undefined”,再來檢視實作該函式的vt_ioctl.c產生的Object檔案,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-objdump -t vt_ioctl.o|grep “vt_ioctl”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vt_ioctl.o: file format elf32-littlearm</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00000000 l df *ABS* 00000000 vt_ioctl.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00000558 g F .text 00001ccc vt_ioctl</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以看到該函式在vt_ioctl.c編譯後,是在text節區中,且屬性為 global,可供外部的.o檔案連結.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後我們檢視drivers/tty/vt目錄下產生的built-in.o,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-objdump -t built-in.o|grep “vt_ioctl”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00000000 l df *ABS* 00000000 vt_ioctl.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00000558 g F .text 00001ccc vt_ioctl</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以看到,最後產生的集合檔案built-in.o,包含了vt.o與vt_ioctl.o,且在其中這些.o之間的Symbol交互參考的問題,都已經在編譯階段被解決.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
想像一下,如果一次有5000個Object檔案或是.a檔案(.a檔案,等於是Object檔案的Archive,可以分辨.o檔案的集合性,但其中所包含的.o並沒有彼此先進行Symbol Resolved,因此,所花的時間成本跟.o是一樣的.),要去做Symbol Resolved,這要建立的對應表格複雜度,跟我先把這5000檔案所在的20個目錄,針對這20個目錄先把其中包含的Object檔案做內部的Symbol Resolved,減少要解決的Symbol個數與要建立的查表範圍,就可以顯著的加速最後要連結成Image的運算時間與記憶體成本.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>參考平台</strong><strong>Tegra2</strong><strong>的記憶體配置</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
筆者以Linux Kernel 2.6.39並選擇ARM Tegra2的平台為例 (NVIDIA Tegra (ARCH_TEGRA)),關於這處理器的基本資訊為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,兩個Cortex A9處理器</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,一個Audio/Video ARM7處理器</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,實體記憶體SDRAM定址在 0x00000000 ( AP20_BASE_PA_SDRAM)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,OnChip 256KB SRAM定址在0x40000000 (AP20_BASE_PA_SRAM)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,NOR Flash的定址在0xD0000000 ( AP20_BASE_PA_NOR_FLASH)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關NVidia Tegra2的資訊可以參考<a href="http://developer.nvidia.com/tegra/taxonomy/term/36/0" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://developer.nvidia.com/tegra/taxonomy/term/36/0</a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>有關</strong><strong>ALT_UP</strong><strong>對</strong><strong>SMP</strong><strong>到</strong><strong>UP</strong><strong>程式碼的修正</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於Linux Kernel SMP的實作,在ARM的架構下會有SMP與單核心共用函式實作程式碼的差異,在檔案 arch/arm/include/asm/assembler.h中,有實現ALT_SMP與ALT_UP兩個巨集,例如在程式碼中使用ALT_UP,該指令就會被加入Section .alt.smp.init 如下所示.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define ALT_UP(instr…) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.pushsection “.alt.smp.init”, “a” ;\</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.long 9998b ;\</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9997: instr ;\</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.if . – 9997b != 4 ;\</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.error “ALT_UP() content must assemble to exactly 4 bytes”;\</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.endif ;\</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.popsection</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
藉此我們可以在同樣的函式中,根據單核心與SMP實作的差異,透過ALT_SMP與ALT_UP來把兩種版本的程式碼置入,以開啟SMP與SMP_ON_UP的實作來說,屬於SMP的實作,會被編譯在原本執行函式的內容中,而屬於單核心版本的實作,則會被編譯到Section .alt.smp.init下,參考如下程式碼的例子</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在檔案arch/arm/mm/proc-v7.S中,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ALT_SMP(orr r0, r0, #TTB_FLAGS_SMP)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ALT_UP(orr r0, r0, #TTB_FLAGS_UP)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cpu_resume_l1_flags:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ALT_SMP(.long PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_FLAGS_SMP)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ALT_UP(.long PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_FLAGS_UP)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或檔案arch/arm/mm/tlb-v7.S中,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ALT_SMP(mcr p15, 0, r0, c8, c3, 1) @ TLB invalidate U MVA (shareable)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ALT_UP(mcr p15, 0, r0, c8, c7, 1) @ TLB invalidate U MVA</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以看到依據SMP與單核心版本的差異,實作上會在同一處程式碼中同時實現兩種版本的程式碼,並透過ALT_UP把單核心的版本在編譯階段放到Section .alt.smp.init中,並且會在每4bytes程式碼位址後,記錄對應4bytes單核心版本指令集,以便修正時參考,如下例子</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc001858c <__smpalt_begin>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc0018634: c0029fd8 .word 0xc0029fd8<strong> //4 bytes </strong><strong>要取代的目標記憶體位址</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc0018638: ee080f37 mcr 15, 0, r0, cr8, cr7, {1} <strong>//4bytes UniProcessor</strong><strong>版本指令</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc001863c: c0029fec .word 0xc0029fec</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc0018640: ee07cfd5 mcr 15, 0, ip, cr7, cr5, {6}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc0018644: c002a00c .word 0xc002a00c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc0018648: ee080f37 mcr 15, 0, r0, cr8, cr7, {1}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在最後的Link階段,會把Section .alt.smp.init放在Symbol __smpalt_begin與__smpalt_end之中,因此在程式碼執行階段,就可以透過這兩個Symbol取得 Section .alt.smp.init中所包含單核心程式碼的內容與記憶體範圍.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Linux Kernel啟動後會呼叫函式__fixup_smp,如果判斷目前是在單核心平台上,就會把在__smpalt_begin到__smpalt_end記憶體範圍的單核心程式碼依據其對應的記憶體位址,進行修正動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
運作概念如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieoqO2PRwMHPFdAFg_PHKX_iyNWEotiQU4OXfdG3qqKMAillENEpxWVZZVguW5Eq0GQjB0r3tvdmx8YvG5Sl4RbHRBX6c39NZq-_YOnKOTkCVfLIDLikuJLPetzvYjnzL_GppFrP7WuRQ/s1600/image001%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="404" data-original-width="642" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieoqO2PRwMHPFdAFg_PHKX_iyNWEotiQU4OXfdG3qqKMAillENEpxWVZZVguW5Eq0GQjB0r3tvdmx8YvG5Sl4RbHRBX6c39NZq-_YOnKOTkCVfLIDLikuJLPetzvYjnzL_GppFrP7WuRQ/s1600/image001%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>從</strong><strong>zImage</strong><strong>開始</strong><strong>,</strong><strong>啟動</strong><strong>Linux Kernel</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,以Linux Kernel zImage為例,簡要說明執行流程,也借此對產生的Linux Kernel Image有一個概念,有關SMP的部份,會在流程走到時,著重說明</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
編譯完成後,在根目錄下的vmlinux會透過如下的命令產生出來,其中有關記憶體位置與節區的配置參考檔案為 arch/arm/kernel/vmlinux.lds</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-ld -EL -p –no-undefined -X –build-id -o <strong><span style="text-decoration-line: underline;">vmlinux</span></strong> -T arch/arm/kernel/vmlinux.lds arch/arm/kernel/head.o arch/arm/kernel/init_task.o init/built-in.o –start-group usr/built-in.o arch/arm/kernel/built-in.o arch/arm/mm/built-in.o arch/arm/common/built-in.o arch/arm/mach-tegra/built-in.o kernel/built-in.o mm/built-in.o fs/built-in.o ipc/built-in.o security/built-in.o crypto/built-in.o block/built-in.o arch/arm/lib/lib.a lib/lib.a arch/arm/lib/built-in.o lib/built-in.o drivers/built-in.o sound/built-in.o firmware/built-in.o net/built-in.o –end-group .tmp_kallsyms2.o</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(</strong><strong>關於</strong><strong> </strong><strong>.tmp_vmlinux1 </strong><strong>與</strong><strong> </strong><strong>.tmp_vmlinux2</strong><strong>的產生</strong><strong>,</strong><strong>在此先略過</strong><strong>)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
之後,執行如下命令把ELF格式的vmlinux轉為 Binary 格式的Image</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-objcopy -O binary -R .comment -S vmlinux arch/arm/boot/Image</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並執行如下命令把 Linux Kernel Binary Image轉為壓縮檔案</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cat arch/arm/boot/compressed/../Image | gzip -f -9 > arch/arm/boot/compressed/piggy.gzip</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考arch/arm/boot/compressed/piggy.gzip.S原始碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.section .piggydata,#alloc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.globl input_data</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
input_data:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.incbin “arch/arm/boot/compressed/piggy.gzip”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.globl input_data_end</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
input_data_end:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以知道在編譯arch/arm/boot/compressed/piggy.gzip.S產生arch/arm/boot/compressed/piggy.gzip.o時,就會把壓縮後的Linux Kernel Image ” arch/arm/boot/compressed/piggy.gzip”,一併產生在piggy.gzip.o中的Symbol input_data與input_data_end之間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然後,把壓縮檔跟解壓縮的部份,連結產生 compressed目錄下的vmlinux <strong>(</strong><strong>記憶體起點為</strong><strong>0x00000000,</strong><strong>也就是對應到</strong><strong>Tegra2</strong><strong>外部記憶體的起點</strong><strong>)</strong>,執行的Link指令如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-ld -EL –defsym _image_size=1602596 –defsym zreladdr=0x00008000 -p –no-undefined -X -T arch/arm/boot/compressed/vmlinux.lds arch/arm/boot/compressed/head.o arch/arm/boot/compressed/piggy.gzip.o arch/arm/boot/compressed/misc.o arch/arm/boot/compressed/decompress.o arch/arm/boot/compressed/lib1funcs.o -o arch/arm/boot/compressed/vmlinux</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然後,執行如下命令把帶有壓縮後的vmlinux與解壓縮程式的ELF格式vmlinux轉為 Binary 格式的zImage</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-objcopy -O binary -R .comment -S arch/arm/boot/compressed/vmlinux arch/arm/boot/zImage</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如此,就完成Linux Kernel Image的產生.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中有關zImage執行的實體記憶體位址可以透過CONFIG_ZBOOT_ROM_TEXT與CONFIG_ZBOOT_ROM_BSS設定.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而Linux Kernel解壓縮的位址會在 CONFIG_ZBOOT_ROM_TEXT + 16kbytes的位址,以這例子來說就是 0x00008000. 這是在最後產生arch/arm/boot/compressd/vmlinux時,透過 “–defsym zreladdr=0x00008000” 產生zreladdr Syombol傳遞給zImage.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以參考 boot/compressed/Makefile中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LDFLAGS_vmlinux += –defsym zreladdr=$(ZRELADDR)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而 ZRELADDR是在arch/arm/boot/Makefile 中設定的</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ZRELADDR := $(zreladdr-y)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中,zreladdr-y會是在每個Machine對應的目錄下的Makefile.boot被定義,例如Tegra2是在檔案 arch/arm/mach-tegra/Makefile.boot中,以如下方式定義zreladdr-y</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
zreladdr-$(CONFIG_ARCH_TEGRA_2x_SOC) := 0x00008000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
同時,對解壓縮的Kernel Image執行的虛擬與實體記憶體對應,必須滿足如下條件</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因為如此,解壓縮的Linux Kernel在虛擬記憶體中的位址就必須是0xc0008000 對應到實體記憶體中的位址會是 0x00008000. 如果Kernel Space的虛擬記憶體空間有調整的話(例如從 0xc0000000調整為0x80000000,就會變成 0x80008000 ↔ 0x00008000).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel Image在虛擬記憶體的運作位置可以透過 xx訂定,一般而言都是給User-Space 3GB的範圍,Kernel Space為1GB的範圍.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
CONFIG_PAGE_OFFSET=0xC0000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要進一步探討Linux Kernel啟動流程,我們可以透arch/arm/boot/compressed/vmlinux.lds了解zImage的啟動流程,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,節區.text產生的Binary Symbol有</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
a,<lext.1135> (“static const unsigned short lext” in lib/zlib_inflate/inftrees.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b,<lbase.1134> (“static const unsigned short lbase” in lib/zlib_inflate/inftrees.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
c,<dext.1137> (“static const unsigned short dext” in lib/zlib_inflate/inftrees.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
d,<dbase.1136> (“static const unsigned short dbase” in lib/zlib_inflate/inftrees.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
e,<lenfix.1621> (“static const code lenfix” in lib/zlib_inflate/inffixed.h)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
f,<distfix.1622> (“static const code distfix” in lib/zlib_inflate/inffixed.h)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
….etc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,會把壓縮後的Linux Kernel piggy.gzip 放在.text節區中Symbol <input_data> 到 <input_data_end>之間,以筆者驗證的環境來說,大約介於實體記憶體 0x00003fde-0x000bdcbe之間. (約761kbytes)<strong>=></strong><strong>要看總共編譯多少核心模組與程式碼範圍.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAGdcdpuMlsKtRKO3BOkN-T_GNeJuWEfP1mUJOSfxDbF64p3aoey6hMHJZCSoOuqihKhVbhA2tgcB2KnlPoUTQjNxQg2gRC3RI9lRQP1W_93oHJPwD8_slHxOc5rfGSxRcSEJ3o2YBrZg/s1600/image002%255B3%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="397" data-original-width="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAGdcdpuMlsKtRKO3BOkN-T_GNeJuWEfP1mUJOSfxDbF64p3aoey6hMHJZCSoOuqihKhVbhA2tgcB2KnlPoUTQjNxQg2gRC3RI9lRQP1W_93oHJPwD8_slHxOc5rfGSxRcSEJ3o2YBrZg/s1600/image002%255B3%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,編譯後的zImage,在會檔頭 offset: 0x00000024 bytes位置存放32-bits 的 “0x016f2818” 作為 BootLoader載入zImage時,確認zImage檔案正確與否的Magic Number. 緊接著offset: 0x00000028位置存放32-bits zImage在實體記憶體的起始位址 <strong></strong><strong>(</strong><strong>以筆者編譯</strong><strong>Tegra2 Seaboard</strong><strong>環境而言該值為</strong><strong> </strong><strong>0x00000000.) </strong>再來的offset: 0x0000002c位置存放32-bits zImage在實體記憶體的結束位置 <strong></strong><strong>(</strong><strong>以筆者編譯</strong><strong>Tegra2 Seaboard</strong><strong>環境而言該值為</strong><strong>0x000bdcf4)</strong>. 透過上述的三個值,就可以讓BootLoader驗證Linux Kernel Magic Number,並且知道要把該Kernel Image擺放到哪一段記憶體位址執行與大小.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,啟動後,會執行arch/arm/boot/compressed/head.S 中的函式start ,可以參考UBoot中呼叫Linux Kernel Entry 的函式原型為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
void (*kernel_entry)(int zero, int arch, uint params);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也就是說, UBoot/BootLoader 呼叫zImage時,第一個參數固定為0(r0),第二個參數為處理器平台ID(r1),第三個參數為Linux Kernel啟動的Boot Argument(r2)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00000000 <start>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000000: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000004: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000008: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000000c: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000010: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000014: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000018: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000001c: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000020: b 30 <_text+0x30></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000024: .word 0x016f2818</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000028: .word 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000002c: .word 0x000bdcf4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000030: mov r7, r1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000034: mov r8, r2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000038: mrs r2, CPSR</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000003c: tst r2, #3 ; 0x3 <strong>(</strong><strong>確認是否為</strong><strong>Supervisor Mode,User Mode=b10000(0x0010) and Supervisor Mode=b10011(0x0013)).</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000040: bne 4c <not_angel></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000044: mov r0, #23 ; 0x17 <strong>(</strong><strong>如果在</strong><strong>SVC Mode</strong><strong>就執行這部份的程式碼</strong><strong>).</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000048: svc 0x00123456 <strong>(ARM semihosting </strong><strong>會傳遞參數</strong><strong>0x17</strong><strong>給</strong><strong>JTAG</strong><strong>除錯器</strong><strong>,</strong><strong>並讓</strong><strong>ARM Core</strong><strong>停止執行</strong><strong>,</strong><strong>可用於</strong><strong>ICE</strong><strong>除錯啟動流程</strong><strong>)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果zImage在編譯時是載入到記憶體0x00000000的位址,則zImage的進入點為 0x00000030. <strong>(</strong><strong>從</strong><strong>0x00000000</strong><strong>開始執行</strong><strong>,</strong><strong>也會執行連續的</strong><strong> </strong><strong>mov r0,r0 </strong><strong>直到</strong><strong>0x00000020</strong><strong>再</strong><strong>Branch</strong><strong>到正式的函式入口</strong><strong>.).</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,之後呼叫函式__armv7_mmu_cache_on,並透過函式setup_mmu以1MB Section方式配置TLB <strong>(MMU</strong><strong>虛擬記憶體機制在這並沒有作用</strong><strong>,</strong><strong>所設定的</strong><strong>TLB</strong><strong>虛擬記憶體是直接對應到</strong><strong>4GB</strong><strong>的範圍</strong><strong>,</strong><strong>所以</strong><strong>TLB</strong><strong>虛擬位址</strong><strong>0xc0000000</strong><strong>就會直接對應到實體記憶體的</strong><strong>0xc0000000.)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
000002bc <__armv7_mmu_cache_on>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002bc: mov ip, lr</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002c0: mrc 15, 0, fp, cr0, cr1, {4} <strong>//read ID_MMFR0</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002c4: tst fp, #15 ; 0xf <strong>//VMSA</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002c8: blne 21c <__setup_mmu></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002cc: mov r0, #0 ; 0x0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002d0: mcr 15, 0, r0, cr7, cr10, {4} <strong>//drain write buffer</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002d4: tst fp, #15 ; 0xf <strong>//VMSA</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002d8: mcrne 15, 0, r0, cr8, cr7, {0} <strong>//flush I,D TLBs</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002dc: mrc 15, 0, r0, cr1, cr0, {0} <strong>//read control reg</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002e0: orr r0, r0, #20480 ; 0x5000 <strong>//I-cache enable, RR cache replacement</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002e4: orr r0, r0, #60 ; 0x3c <strong>//write buffer</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002e8: orrne r0, r0, #1 ; 0x1 <strong>//MMU enabled</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002ec: mvnne r1, #0 ; 0x0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002f0: mcrne 15, 0, r3, cr2, cr0, {0} <strong>//load page table pointer //r3 from setup_mmu = page table entry.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002f4: mcrne 15, 0, r1, cr3, cr0, {0} <strong>//load domain access control</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002f8: mcr 15, 0, r0, cr1, cr0, {0} <strong>//load control register</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x000002fc: mrc 15, 0, r0, cr1, cr0, {0} <strong>//and read it back</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000300: mov r0, #0 ; 0x0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000304: mcr 15, 0, r0, cr7, cr5, {4} <strong>//ISB</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000308: mov pc, ip</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0000021c <__setup_mmu>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000021c: sub r3, r4, #16384 ; 0x4000 <strong>//Page directory size //(r4=Linux Kernel </strong><strong>解壓縮後記憶體位址</strong><strong> </strong><strong>=0x00008000, r3=0x00004000)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000220: bic r3, r3, #255 ; 0xff <strong>//Align the pointer</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000224: bic r3, r3, #16128 ; 0x3f00</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/* Initialise the page tables, turning on the cacheable and bufferable</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* bits for the RAM area only. */</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000228: mov r0, r3</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000022c: lsr r9, r0, #18</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000230: lsl r9, r9, #18 <strong>//start of RAM</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000234: add sl, r9, #268435456 ; 0x10000000 <strong>// a reasonable RAM size</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000238: mov r1, #18 ; 0x12</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000023c: orr r1, r1, #3072 ; 0xc00</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000240: add r2, r3, #16384 ; 0x4000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000244: cmp r1, r9 <strong>//if virt > start of RAM</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000248: orrcs r1, r1, #12 ; 0xc <strong>//set cacheable, bufferable</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000024c: cmp r1, sl <strong>//if virt > end of RAM</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000250: biccs r1, r1, #12 ; 0xc <strong>//clear cacheable, bufferable</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000254: str r1, [r0], #4 <strong>//1:1 mapping</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000258: add r1, r1, #1048576 ; 0x100000 <strong>//Use Section Size=1MB//Page Table</strong><strong>從</strong><strong>0x4000-0x8000,</strong><strong>每個</strong><strong>Entry</strong><strong>值為</strong><strong>4 bytes,</strong><strong>所以會有</strong><strong>0x1000</strong><strong>筆</strong><strong>Entry,</strong><strong>也就是說</strong><strong>0x1000 * 1MB=4GB Range=32bits</strong><strong>處理器訂址的上限</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000025c: teq r0, r2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000260: bne 244 <__setup_mmu+0x28></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/* If ever we are running from Flash, then we surely want the cache</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* to be enabled also for our execution instance… We map 2MB of it</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* so there is no map overlap problem for up to 1 MB compressed kernel.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* If the execution is in RAM then we would only be duplicating the above. */</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000264: mov r1, #30 ; 0x1e</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000268: orr r1, r1, #3072 ; 0xc00</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000026c: mov r2, pc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000270: lsr r2, r2, #20</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000274: orr r1, r1, r2, lsl #20</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000278: add r0, r3, r2, lsl #2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000027c: str r1, [r0], #4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000280: add r1, r1, #1048576 ; 0x100000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000284: str r1, [r0]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000288: mov pc, lr</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關TLB 1MB Section Settings如下示意圖</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgifEFq_kV4dyKCziyu-84gcv8Hfn16qYoxiPcCFRKknq10kUeotK1DKgQbKmOH98qZ9sffD74Tb3_BDwRRMIx8Q6jk7qzMqCkGA-DAvycbGFE4yA316kPINtmVYWViVzfV_9YV10UC944/s1600/image003%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="435" data-original-width="639" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgifEFq_kV4dyKCziyu-84gcv8Hfn16qYoxiPcCFRKknq10kUeotK1DKgQbKmOH98qZ9sffD74Tb3_BDwRRMIx8Q6jk7qzMqCkGA-DAvycbGFE4yA316kPINtmVYWViVzfV_9YV10UC944/s1600/image003%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以配置在0x00004000-0x00008000之間TLB 1MB Section的虛擬記憶體設定來說,Linux Kernel Base Address 0xc0008000,透過TLB查尋0xc0000000對應到的實體記憶體位址,首先取虛擬記憶體bits 31-20 值0xc00 作為Table Index,得到的Translation Table Base Address為 0x00004000 + 0xc00*4 = 0x00007000,該記憶體位址的1st Level Descriptor內容為0xc0000c12,屬性欄位為 1100 0001 0010 也就是AP[2:0]=011(Privileged/User permissions 都是可讀可寫的Full Access Right.),XN=1,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用虛擬記憶體0xc0008000轉換為實體記憶體時,1st Level Descriptor的bit 31-20 為0xc0000000+Offset 0x00008000=實體記憶體0xc0008000.<strong> (</strong><strong>這是只有經過</strong><strong>zImage</strong><strong>前面</strong><strong>setup_mmu</strong><strong>設定的結果</strong><strong>,</strong><strong>並非正式</strong><strong>Linux Kernel MMU TLB</strong><strong>的配置結果喔</strong><strong>!!!)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
雖然setup_mmu已經對MMU TLB進行配置,但還不是最後的運作狀態,會在後續執行中設定完成.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6, 之後透過ARM r4暫存器 (r4 = kernel execution address )儲存Linux Kernel所要解壓縮的目標記憶體位置,如下程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef CONFIG_AUTO_ZRELADDR</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@ determine final kernel image address</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r4, pc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
and r4, r4, #0xf8000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
add r4, r4, #TEXT_OFFSET</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#else</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ldr r4, =zreladdr</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bl cache_on</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
呼叫函式decompress_kernel,解壓縮Linux到目標位址</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/*</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* The C runtime environment should now be setup sufficiently.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* Set up some pointers, and start decompressing.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* r4 = kernel execution address</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* r7 = architecture ID</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* r8 = atags pointer</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*/</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r0, r4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r1, sp @ malloc space above stack</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
add r2, sp, #0x10000 @ 64k max</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r3, r7</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bl decompress_kernel</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bl cache_clean_flush</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bl cache_off</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r0, #0 @ must be zero</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r1, r7 @ restore architecture number</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r2, r8 @ restore atags pointer</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov pc, r4 @ call kernel</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式decompress_kernel 第一個參數為Linux Kernel要解壓縮的目標記憶體位置(from r4),第二個參數為目前的Stack Point,第三個參數為目前Stack加上64kbytes,第四個參數為目前的處理器平台識別碼,之後Flush Cache並關閉Cache.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後,從Linux Kernel解壓縮後的記憶體位置的起點(也就是r4的記憶體位置)開始執行Linux Kernel<strong> (</strong><strong>第一個參數為</strong><strong>0, </strong><strong>第二個參數為目前的處理器平台識別碼</strong><strong>,</strong><strong>第三個參數為</strong><strong>BootLoader</strong><strong>要傳遞給</strong><strong>Linux Kernel</strong><strong>的</strong><strong>Boot Argument.)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
整個ARM從Boot Rom到UBoot BootLoader ,到 zImage解壓縮,到啟動解壓縮後Linux Kernel的流程,簡要描述如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNl2KUUreBjJhqjcLtVVryGpOSmJ3-7JEWEDYI8sUt4wcMceKUGqGnHABo8tlymbPqnQPHFkNEcq9D_veFz6bYPgFgUW8z2rCLlsp1ZQW40BXMEaWNFXKDBKDDuhw61yG-fyMDyravTeM/s1600/image004%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="382" data-original-width="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNl2KUUreBjJhqjcLtVVryGpOSmJ3-7JEWEDYI8sUt4wcMceKUGqGnHABo8tlymbPqnQPHFkNEcq9D_veFz6bYPgFgUW8z2rCLlsp1ZQW40BXMEaWNFXKDBKDDuhw61yG-fyMDyravTeM/s1600/image004%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
結束了zImage到解壓縮後的vmlinux Kernel Image流程,接下來我們以開啟SMP選項的Linux Kernel Image為例,進一步說明啟動的流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>繼續</strong><strong>vmlinux Linux Kernel Image</strong><strong>執行流程</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最原始的ELF格式Linux Kernel在編譯後所在的位置為/vmlinux,透過objcopy產生的Binary檔案為 arch/arm/boot/Image.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根目錄的vmlinux執行時,會從arch/arm/kernel/head.S中的函式stext開始,stext函式會帶入三個函式參數,第一個參數固定為0,第二個參數為architecture number,第三個參數為要帶給Kernel參數在記憶體中的位址.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為反組譯vmlinux執行時最前端的程式碼,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008000 <stext>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008000: msr CPSR_c, #211 ; 0xd3 <strong>//ensure svc mode and irqs disabled</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008004: mrc 15, 0, r9, cr0, cr0, {0} <strong>//get processor id</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008008: bl 0x00156878 <__lookup_processor_type><strong> //r5=procinfo r9=cpuid</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000800c: movs sl, r5 <strong>//invalid processor (r5=0)?</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008010: beq c01568bc <__error><strong> //yes, error ‘p’</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008014: add r3, pc, #40 ; 0x28</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008018: ldm r3, {r4, r8}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000801c: sub r4, r3, r4 <strong>//(PHYS_OFFSET – PAGE_OFFSET)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008020: add r8, r8, r4<strong> //PHYS_OFFSET</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>/*r1 = machine no, r2 = atags,</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>* r8 = phys_offset, r9 = cpuid, r10 = procinfo */</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008024: bl 0x0000810c <__vet_atags></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008028: bl 0x00008144 <__fixup_smp>/<strong>/</strong><strong>用以修正</strong><strong>SMP Linux Kernel</strong><strong>在單核心處理器運作的機制</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000802c: bl 0x0000804c <__create_page_tables> /<strong>/</strong><strong>設定</strong><strong>BootStrap</strong><strong>處理器的</strong><strong>MMU TLB</strong><strong>分頁表</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008030: ldr sp, [pc, #8] ; 0x00008040 <stext+0x40><strong> //address to jump to after mmu has been enabled</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008034: add lr, pc, #0 ; 0x0 <strong>//return (PIC) address</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008038: add pc, sl, #16 ; 0x10 <strong>//Go to function __v7_proc_info (0x0019abf8+0x10 = 0x0019ac08)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000803c: b 0x0015684c <__enable_mmu></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008040: .word 0xc00081a0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008044: .word 0xc0008044</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00008048: .word 0xc0000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在前面的內容有提到,透過setup_mmu所配置的MMU TLB並不是一個真正適應於Linux Kernel最終在高位址執行設定的虛擬記憶體配置,而在這階段透過函式__create_page_tables,就會把MMU TLB從下圖左側原本的配置方式,改為如右側適應於Linux Kernel配置在高位址,並且針對不存在的記憶體分頁,設定為0.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZuDl4t9j7AvKkC9Iau7wf_716zkAbrmCQsvGGI1t_BYYeVKIM6vg8zQ1PmrHmhZBio2RNUeuy7RCqdoHZk_GUX60kQcKVOJJdmJQvofGLANmOn382YnsQRsOFN6UUWoltfl2EyVQe1FY/s1600/image005%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="466" data-original-width="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZuDl4t9j7AvKkC9Iau7wf_716zkAbrmCQsvGGI1t_BYYeVKIM6vg8zQ1PmrHmhZBio2RNUeuy7RCqdoHZk_GUX60kQcKVOJJdmJQvofGLANmOn382YnsQRsOFN6UUWoltfl2EyVQe1FY/s1600/image005%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果我們所編譯的Linux Kernel為支援SMP的版本,並且有開啟編譯選項SMP_ON_UP,在函式 __fixup_smp中 (fixup = Fix UniProcessor),會進行確認是否為SMP的核心運作在單核心處理器上,並執行必要的修正.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在ARMv7 Cortex處理器下,會進入函式__v7_proc_info + 0x10 也就是函式__v7_setup中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0019abf8 <__v7_proc_info>: (in arch/arm/mm/proc-v7.S)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0019abf8: .word 0x000f0000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0019abfc: .word 0x000f0000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0019ac00: .word 0x00011c0e</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0019ac04: .word 0x00000c12</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0019ac08: b 0x001570bc <__v7_setup></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在函式__v7_setup中會初始化TLB,Caches與MMU. 並透過CP15取得Main ID Register, 簡要說明如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過”MRC p15, 0, <Rd>, c0, c0, 0″ 讀取處理器Main ID Register</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Cortex A8 單核心 Main</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Cortex A9 單核心 Main</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Cortex A9 Dual-Core Main ID= 0x412FC090 (for r2p0) ,0x412FC091 (for r2p1) or 0x412FC092 (for r2p2)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Main ID Register格式如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>31</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>30</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>29</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>28</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>27</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>26</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>25</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="19"><strong>24</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="21"><strong>23</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>22</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>21</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="21"><strong>20</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="19"><strong>19</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>18</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>17</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>16</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>15</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>14</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>13</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>12</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>11</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>10</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>9</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="21"><strong>8</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="19"><strong>7</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>6</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>5</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="21"><strong>4</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="19"><strong>3</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>2</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="20"><strong>1</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="31"><strong>0</strong></td></tr>
<tr><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="160"><strong>Implementor</strong></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="82"><strong>Variant</strong></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="79"><strong>Architecture</strong></td><td colspan="12" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="242"><strong>Primary Part Number</strong></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="90"><strong>Revision</strong></td></tr>
</tbody></table>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="178">欄位</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="469">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="178">Implementor</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="469">ARM處理器為0x41</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="178">Variant</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="469">可用以表示Major Revision<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Indicates the variant number, or major revision, of the processor:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x3.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="178">Architecture</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="469">Indicates that the architecture is given in the feature registers:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xF.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="178">Primary Part Number</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="469">Indicates the part number, Cortex-A8:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xC08.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="178">Revision</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="469">Indicates the revision number, or minor revision, of the processor:<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x2.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式__v7_setup運作如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570bc <__v7_setup>: (in arch/arm/mm/proc-v7.S)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570bc: add ip, pc, #140 ; 0x8c <strong>//the local stack</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570c0: stm ip, {r0, r1, r2, r3, r4, r5, r7, r9, fp, lr}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570c4: bl 0x000297ec <v7_flush_dcache_all></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570c8: ldm ip, {r0, r1, r2, r3, r4, r5, r7, r9, fp, lr}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570cc: mrc 15, 0, r0, cr0, cr0, {0}<strong> //read main ID register</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570d0: and sl, r0, #-16777216 ; 0xff000000<strong><span style="text-decoration-line: underline;"> //ARM?</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570d4: teq sl, #1090519040 ; 0x41000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570d8: bne 0x00157108 <__v7_setup+0x4c></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570dc: and r5, r0, #15728640 ; 0xf00000 <strong>//variant</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570e0: and r6, r0, #15 ; 0xf <strong>//revision</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570e4: orr r6, r6, r5, lsr #16 <strong>//combine variant and revision</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570e8: ubfx r0, r0, #4, #12 <strong>//primary part number</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570ec: ldr sl, [pc, #136] ; 0x0015717c <__v7_setup_stack+0x2c><strong> //Cortex-A8 primary part number</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570f0: teq r0, sl</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570f4: bne 0x001570fc <__v7_setup+0x40></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570f8: b 0x00157108 <__v7_setup+0x4c></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x001570fc: ldr sl, [pc, #124] ; 0x00157180 <__v7_setup_stack+0x30><strong>//Cortex-A9 primary part number</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157100: teq r0, sl</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157104: bne 0x00157108 <__v7_setup+0x4c></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157108: mov sl, #0 ; 0x0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0015710c: dsb sy</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157110: mcr 15, 0, sl, cr8, cr7, {0}<strong> //invalidate I + D TLBs</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157114: mcr 15, 0, sl, cr2, cr0, {2} <strong>//TTB control register</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157118: orr r4, r4, #106 ; 0x6a</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0015711c: mcr 15, 0, r4, cr2, cr0, {1} <strong>//load TTB1</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157120: ldr r5, [pc, #92] ; 0x00157184 <__v7_setup_stack+0x34><strong> //PRRR</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157124: ldr r6, [pc, #92] ; 0x00157188 <__v7_setup_stack+0x38><strong> //NMRR</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157128: mcr 15, 0, r5, cr10, cr2, {0} <strong>//write PRRR</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0015712c: mcr 15, 0, r6, cr10, cr2, {1} <strong>//write NMRR</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157130: add r5, pc, #16 ; 0x10</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157134: ldm r5, {r5, r6}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157138: mrc 15, 0, r0, cr1, cr0, {0} <strong>//read control register</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0015713c: bic r0, r0, r5 <strong>//clear bits them</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157140: orr r0, r0, r6<strong> //set them</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00157144: mov pc, lr <strong>//pc=0x0000803c,</strong><strong>之後進入</strong><strong> </strong><strong>函式</strong><strong> </strong><strong>__enable_mmu</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
回到stext函式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0000803c: b 0x0015684c <__enable_mmu></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
進入函式 __enable_mmu</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0015684c <__enable_mmu>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0015684c: orr r0, r0, #2 ; 0x2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156850: mov r5, #21 ; 0x15</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156854: mcr 15, 0, r5, cr3, cr0, {0}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156858: mcr 15, 0, r4, cr2, cr0, {0}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0015685c: b 0x00156860 <__turn_mmu_on></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
進入函式 __turn_mmu_on</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156860 <__turn_mmu_on>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156860: nop (mov r0,r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156864: mcr 15, 0, r0, cr1, cr0, {0}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156868: mrc 15, 0, r3, cr0, cr0, {0}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x0015686c: mov r3, r3</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156870: mov r3, sp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00156874: mov pc, r3<strong> //</strong><strong>會呼叫</strong><strong>0xc00081a0 <span style="text-decoration-line: underline;">//</span></strong><strong><span style="text-decoration-line: underline;">到這就是第一次執行到虛擬記憶體的位址</span></strong><strong><span style="text-decoration-line: underline;"> </span></strong><strong><span style="text-decoration-line: underline;">0xc00081a0</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
進入函式__mmap_switched</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081a0 <__mmap_switched>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081a0: add r3, pc, #64 ; 0x40</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081a4: ldm r3!, {r4, r5, r6, r7}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081a8: cmp r4, r5 <strong>//Copy data segment if needed</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081ac: cmpne r5, r6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081b0: ldrne fp, [r4], #4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081b4: strne fp, [r5], #4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081b8: bne c00081ac <__mmap_switched+0xc></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081bc: mov fp, #0 ; 0x0 <strong>//Clear BSS (and zero fp)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081c0: cmp r6, r7</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081c4: strcc fp, [r6], #4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081c8: bcc c00081c0 <__mmap_switched+0x20></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081cc: ldm r3, {r4, r5, r6, r7, sp}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081d0: str r9, [r4] <strong>//Save processor ID</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081d4: str r1, [r5] <strong>//Save machine type</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081d8: str r2, [r6] <strong>//Save atags pointer</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081dc: bic r4, r0, #2 ; 0x2 <strong>//Clear ‘A’ bit</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0xc00081e0: stm r7, {r0, r4} <strong>//Save control register values </strong><br />0xc00081e4: b 0xc00088ac <start_kernel><strong> //</strong><strong>正式進入</strong><strong>Linux Kernel Starting</strong>.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式start_kernel實作在 init/main.c中,並且start_kernel啟動主要Linux核心的初始化與包括Kernel SMP機制的初始化, 有關從Linux Kernel stext到start_kernel 執行的流程示意圖,如下所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCUT8LPOVjC0yQ7LOQ-nFyrDj1JVWAkblzUhKG24feTJsAQW477kpT-ZVynDZ-DURP6ce7lWhU27F3veTZ2cUq7G1Mi2yQ5-3-919PoryP6Fgr2I5-YqvhKzEZlJce9aFATMSRbUJG4Hg/s1600/image006%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="568" data-original-width="448" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCUT8LPOVjC0yQ7LOQ-nFyrDj1JVWAkblzUhKG24feTJsAQW477kpT-ZVynDZ-DURP6ce7lWhU27F3veTZ2cUq7G1Mi2yQ5-3-919PoryP6Fgr2I5-YqvhKzEZlJce9aFATMSRbUJG4Hg/s1600/image006%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>start_kernel</strong><strong>的流程</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在init/main.c中的start_kernel函式為整個Linux核心啟動的主體,接下來我們針對流程簡要說明,在有關SMP部分,會特別強調它的運作行為.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其實探究每一個步驟的細節,是做技術的人最快樂的事情,但如果每個步驟都挖到最深入,就真的像是老太婆的裹腳布一樣又臭又長(雖然本文已經快要又臭又長了…),所以會選擇筆者自己覺得值得深入的動作加以說明,如果我覺得那不必要成為文章中的一部分,就會主動跳過,不另外提及. 有興趣的讀者,也可自行參閱Linux Kernel原碼.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
整理後的內容如下所示</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">start_kernel<br />初始化函式的流程</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">smp_setup_processor_id</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">Do nothing in ARM.</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">此時中斷是關閉的,直到下述必要的程序走完,才會重新開啟中斷</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">tick_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">In kernel/time/tick-common.c<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
呼叫clockevents_register_notifier註冊 Clock Event.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">boot_cpu_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">會初始化第一個處理器,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
include/linux/smp.h:# define smp_processor_id() raw_smp_processor_id()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
define smp_processor_id() raw_smp_processor_id()</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在沒有設定SMP的Kernel中raw_smp_processor_id定義為0,所以處理器ID會固定為0.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在有設定SMP的Kernel中,smp_processor_id (=raw_smp_processor_id)會傳回目前正在執行該程序的處理器ID.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arch/arm/include/asm/smp.h:#define raw_smp_processor_id() (current_thread_info()->cpu)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
呼叫函式set_cpu_online,set_cpu_active,set_cpu_present與set_cpu_possible,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
讓目前使用的處理器設定為Online,Active,Present與Prosible,在SMP的架構下,通常會用第一個處理器(CPU)作為初始化的處理器.</div>
</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">顯示字串 “Linux version 2.6.39 (root@localhost.localdomain) (gcc version 4.4.0(GCC) ) #11 SMP Thu Jul xx aa:bb:cc EDT 2011″</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">setup_arch</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">函式實作在arch/arm/kernel/setup.c,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,呼叫unwind_init,初始化基於ARM EABI的Backtrace Unwind機制 (in arch/arm/kernel/unwind.c). 處理BootLoader傳遞給Linux Kernel(in __atags_pointer)的參數. 設定code(_text,_etext),data(_sdata,_end),System Ram,Video Ram,I/O記憶體資源</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫is_smp (in arch/arm/include/asm/smp_plat.h)判斷目前是否運作在SMP Kernel下,總共可以有三種組合</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
a,沒有設定CONFIG_SMP,會直接返回 false.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b,有設定CONFIG_SMP_ON_UP,表示可以支援SMP Kernel運作在UniProcessor(單核心)的處理器上,這時會以smp_on_up的值判斷SMP Kernel是否有運作在單核心處理器上.若是則會返回false.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
c,反之則返回 true,表明目前是在SMP Kernel運作下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3,</strong><strong>承上,</strong><strong>如果確認是在SMP</strong><strong>下,</strong><strong>會呼叫smp_init_cpus (in mach-tegra/platsmp.c), </strong><strong>並透過函式scu_get_core_count(in arch/arm/kernel/smp_scu.c)</strong><strong>取得處理器個數, </strong><strong>與透過cpu_set(in include/linux/cpumask.h)</strong><strong>設定Cpumasks (</strong><strong>為一個bitmap,</strong><strong>每個bit</strong><strong>代表系統中對應存在的一個處理器), </strong><strong>會透過NR_CPUS</strong><strong>決定Cpumasks bitmap</strong><strong>的大小,</strong><strong>以ARM</strong><strong>平台為例,</strong><strong>代表SMP</strong><strong>支援處理器個數的NR_CPUS</strong><strong>範圍可以為2</strong><strong>到32.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,預留記憶體給Linux Kernel崩潰時使用,配置IRQ/Abort/Undefined Instruction Mode的Stack,並回到SVC Mode.(此時IRQ/FIQ中斷都還是維持關閉的狀態)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,呼叫tcm_init,根據arch/arm/kernel/vmlinux.lds.S中Linker Section的配置, 從外部記憶體__dtcm_start,把DTCM資料搬到__sdtcm_data到__edtcm_data中, 從外部記憶體__itcm_start,把ITCM程式碼搬到__sitcm_text到__eitcm_text中.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,呼叫early_trap_init (in arch/arm/kernel/traps.c),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據CONFIG_VECTORS_BASE (在ARM上通常為0xffff0000,可以避免設定Vector在0x00000000時,變成無法對0x00000000設定不可讀/不可寫與不可執行的動作,用以抓出系統可能對0位址的讀寫或是Function Null Pointer的錯誤偵測=>這招在產品開發上很好用!!).</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,參考arch/arm/kernel/entry-armv.S.會在0xffff0000配置Vector Table(複製來源為__vectors_start到__vectors_end).在0xffff0200之後配置Vector Stubs(複製來源為__stubs_start到__stubs_end),在中斷觸發後Branch這,之後Branch到對應CPU Mode的對應Vector處理Handlers. 在(0xffff0000+0x1000-(__kuser_helper_end – __kuser_helper_start) )之後配置User Helpers(複製來源為__kuser_helper_start到__kuser_helper_end),每個User Helpers的Segment為32bytes alignment,主要用以由Kernel這提供給User Mode運作的操作,以提高處理的效率,支援的函式包括__kernel_cmpxchg,__kernel_get_tls,__kernel_helper_version. 因此,觸發中斷的流程為,先到0xffff0000對應的中斷,透過Branch到Vector Stubs,再由Vector Strubs到對應的User Mode/SVC Mode的中斷處理函式,例如IRQ中斷觸發後,透過0x00000018到vector_irq再到__irq_usr或__irq_svc中斷處理函式.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,執行Machine Descriptor 的init_early</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">setup_nr_cpu_ids</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499"><strong>實作在檔案kernel/smp.c</strong><strong>中,</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>會呼叫find_last_bit</strong><strong>去尋找Cpumaks</strong><strong>中最後設定的bits,</strong><strong>用以決定在SMP</strong><strong>中支援的處理器個數. </strong><strong>結果會儲存在變數nr_cpu_ids.</strong></div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">setup_per_cpu_areas</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499"><strong>實作在檔案mm/percpu.c</strong><strong>中,</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>針對單核心與SMP</strong><strong>有不同的實作,</strong><strong>用以配置每個處理器在記憶體中的變數區域.</strong></div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">smp_prepare_boot_cpu</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499"><strong>//arch-specific boot-cpu hooks</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>實作在檔案arch/arm/kernel/smp.c</strong><strong>中,</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>設定目前處理器的idle</strong><strong>為目前的Process ID.</strong></div>
</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">呼叫函式build_all_zonelists,page_alloc_init,parse_early_param..etc</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">These use large bootmem allocations and must precede kmem_cache_init()</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">pidhash_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/pid.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
產生搭配O(1) Scheduling的PID Hash Table,</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">vfs_caches_init_early</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案fs/dcache.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會再呼叫dcache_init_early與inode_init_early</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">sort_main_extable</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/extable.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
呼叫sort_extable(in sort_extable)對Linux Kernel中的built-in exception table進行排序</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">mm_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">配置Linux Kernel memory allocators</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">Set up the scheduler prior starting any interrupts (such as the timer interrupt). Full topology setup happens at smp_init() time – but meanwhile we still have a functioning scheduler.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">sched_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/sched.c中.<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化支援多核心的排程機制.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
後續還會在kernel_init中呼叫函式sched_init_smp</div>
</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">Disable preemption – early bootup scheduling is extremely fragile until we cpu_idle() for the first time.</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">呼叫函式preempt_disable與irqs_disabled關閉Preemptive Scheduling與IRQ.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">idr_init_cache</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案lib/idr.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
for “Small id to pointer translation service.”</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">rcu_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499"><strong>實作在檔案kernel/rcutree.c</strong><strong>中</strong><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>用以初始化Read Copy Update</strong><strong>機制.</strong><strong>這是Linux Kernel</strong><strong>在2.5</strong><strong>版本後所支援的同步(synchronization)</strong><strong>機制,</strong><strong>可用以確保當有多個Reader</strong><strong>讀取同一個資料時,</strong><strong>在同一個Grace</strong><strong>週期中,</strong><strong>所有Reader</strong><strong>讀取到的內容都是一致的.</strong><strong>參考Linux Kernel Documentation</strong><strong>的內容,RCU</strong><strong>讀取的範例如下</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>rcu_read_lock();</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>p = rcu_dereference(head.next);</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>y = p->data;</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>rcu_read_unlock();</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>尤其是在有多核心(SMP)</strong><strong>的架構下,</strong><strong>當透過RCU</strong><strong>機制保護的資料結構被更動時,</strong><strong>有RCU</strong><strong>保護的內容,</strong><strong>在rcu_read_lock/rcu_read_unlock</strong><strong>之間,</strong><strong>可以確保每個處理器上在這狀態下每個Process</strong><strong>所讀取的同一個資料結構內容都是一致的.</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>RCU</strong><strong>是一個在多核心下,</strong><strong>很值得善用的資料同步機制,</strong><strong>筆者會在後續有專文討論.</strong></div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">radix_tree_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案lib/radix-tree.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以初始化Radix Tree,作為快速查找的搜尋樹.在Linux Kernel中包括Cache機制,也有採用這資料結構加速效能.</div>
</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">init some links before init_ISA_irqs()</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">early_irq_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/irq/irqdesc.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會初始化IRQ Descriptor,這機制主要用以抽象化Device Driver處理的Interrupt Handler,讓Device Driver不需要因為平台的差異,而去因應對於中斷的處理行為. (可以透過一致的函式去request, enable, disable 與 free interrupts),可以參考文件<a href="http://www.kernel.org/doc/htmldocs/genericirq.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.kernel.org/doc/htmldocs/genericirq.html</a> .</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">init_IRQ</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案arch/arm/kernel/irq.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用以呼叫每個平台差異下,各自實作的函式 “init_irq”,以Tegra而言會進入函式tegra_init_irq中.(in arch/arm/mach-tegra/irq.c)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">prio_tree_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案lib/prio_tree.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化priority search tree.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">init_timers</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/timer.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化支援SMP架構的 per-CPU timer.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">hrtimers_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/hrtimer.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化High-resolution kernel timers (相對於kernel/timers中支援的milliseconds sleep,在這機制下可以支援nanoseconds sleep)</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">softirq_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/softirq.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化Soft IRQ,這是在Linux Kernel中支援Soft IRQ Thread的機制,用以執行基於Kernel Thread的 Interrupt Bottom Halves (也就是一般RTOS下的HISR機制.)(參考網頁 <a href="http://elinux.org/Soft_IRQ_Threads" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://elinux.org/Soft_IRQ_Threads</a> )</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">timekeeping_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/time/timekeeping.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化Generic Timekeeping Subsystem,用以更新系統的流逝時間,會更新xtime,wall_to_monotonic與total_sleep_time,並負責較整誤差(包括從系統Suspend到Resume的時間差),支援getnstimeofday,do_gettimeofday,do_settimeofday…etc函式.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(參考網頁<a href="http://book.opensourceproject.org.cn/kernel/kernel3rd/opensource/0596005652/understandlk-chp-6-sect-2.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://book.opensourceproject.org.cn/kernel/kernel3rd/opensource/0596005652/understandlk-chp-6-sect-2.html</a> )</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">time_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案arch/arm/kernel/time.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會初始化平台上的System Timer,以Tegra為例,會依據每個平台的實作,透過machine_desc->timer進入函式tegra_init_timer (in arch/arm/mach-tegra/timer.c)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">local_irq_enable</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">在這會透過CPSR確認IRQ是否有被提前Enable,與指令”cpsie i” 開啟Local IRQ. (可以參考arch/arm/include/asm/irqflags.h中arch_local_irq_enable的實作.)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CPSIE i (Enable irq)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CPSID i (Disable irq)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CPSIE f (Enable fiq)</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>CPSID f (Disable fiq)</strong></div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">console_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案drivers/tty/tty_io.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Initialize the console device early.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">setup_per_cpu_pageset</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案mm/page_alloc.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在這會幫每個處理器配置Page Table. 原本只有啟動時,在Bootstrap處理器TLB針對Linux Kernel的Page 1MB Section配置. (Page Table的配置會抽空進一步說明)</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">sched_clock_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/sched_clock.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化每個處理器的Schedule Clock Data,並支援sched_clock傳回系統開機到目前經過的nanoseconds時間值.(透過 jiffies (每一次Timer-Interrupr加一),與 HZ(HZ為每一秒的Timer Interrupt次數 (以Tegra而言定義為CONFIG_HZ=100))計算.)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">calibrate_delay</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案init/calibrate.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這函式就是著名的BogoMIPS(Bogo Millions Instructions Per Second)計算函式,會產生loops_per_jiffy值,並用以算出最後的BogoMIPS.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
開機過程會顯示 ”Calibrating delay loop (skipped), value calculated using timer frequency.. AAA.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BB BogoMIPS (lpj=CCCCC)”. 可以透過這網頁<a href="http://www.clifton.nl/bogo-list.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.clifton.nl/bogo-list.html</a> 知道不同處理器所對應的BogoMIPS.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">pidmap_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/pid.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Generic pidhash and scalable, time-bounded PID allocator.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會參考處理器的數量,訂定PID數量範圍,並配置PID Map記憶體.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">anon_vma_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案mm/rmap.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化Anonymous VMA(Virtual Memory Area)機制.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡要來說記憶體的Page Mapping可以分為</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,Anonymous Page: 只要不是屬於以檔案內容進行的記憶體Mapping,就屬此類.例如: <strong>“mmap(NULL, Size, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);”</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,File-Mapped Page: 以檔案為記憶體Mapping的分頁. 例如: <strong>“mmap(NULL, Size, PROT_READ|PROT_WRITE, MAP_PRIVATE, vFile, 0);”</strong></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也可以參考這網頁的說明</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<a href="http://linuxkernelpanic.blogspot.com/2010/05/while-getting-in-touch-recently-with-ex.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://linuxkernelpanic.blogspot.com/2010/05/while-getting-in-touch-recently-with-ex.html</a></div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">cred_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/cred.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化Credentials,這是在Linux Kernel中用來管控權限的機制,包括在User Mode的Task要去執行系統呼叫(System Call)時,Task Capability的安全稽核機制,會呼叫current_cred取得目前Task的Credentials,並確認該Task是否具備可以執行該系統呼叫的權限,確保系統的安全性. 防止沒有經過授權的使用者Task,去進行屬於特權等級使用者的動作.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">fork_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/fork.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化fork機制,會參考totalram_pages決定可以fork的行程數量max_threads.(最低不小於20個),</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">proc_caches_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/fork.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
配置行程Process所需的Slab Cache,包括sighand/signal/files/fs/mm_struct/vm_area_struct cache,並執行函式mmap_init</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">buffer_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案fs/buffer.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化FileSystem Buffer,會呼叫nr_free_buffer_pages取得目前系統Free的空間值,並定義最大不超過該值的10%,作為FileSystem Buffer的空間.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">vfs_caches_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案fs/dcache.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化VFS的 dcache跟inode Cache.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">signals_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案kernel/signal.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化Signal Queue</div>
</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="647">rootfs populating might need page-writeback</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">page_writeback_init</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案mm/page-writeback.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用來初始化檔案系統中用來作為Cache的記憶體Writeback回儲存媒體的機制,會產生pdflush Kernel Thread執行Dirty Page Writeback的流程.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般來說,有兩種情況會觸發pdflush流程</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,當系統Free Memory過低,進行Shrink Page時,可透過pdflush回寫到磁碟釋放出記憶體.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,當Dirty Page數量達到一個值或是相對比例時.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Linux Kernel 2.6.39文件Documentation/sysctl/vm.txt,透過檔案/proc/sys/vm/nr_pdflush_threads可知道目前啟動的pdflush daemon數量(這要視系統Runtime Dirty Pages的情況而定). 此外,透過設定/proc/sys/vm/dirty_background_ratio <strong><span style="text-decoration-line: underline;">(</span></strong><strong><span style="text-decoration-line: underline;">以相對</span></strong><strong><span style="text-decoration-line: underline;">System Memory</span></strong><strong><span style="text-decoration-line: underline;">的百分比</span></strong><strong><span style="text-decoration-line: underline;">)</span></strong>或/proc/sys/vm/dirty_background_bytes <strong>(</strong><strong>以</strong><strong>Dirty Memory</strong><strong>數量</strong><strong>)</strong>二則一,可設定觸發pdflush daemon進行Page Writeback的條件.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(可以參考網頁<a href="http://www.westnet.com/~gsmith/content/linux-pdflush.htm" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.westnet.com/~gsmith/content/linux-pdflush.htm</a> 或<a href="http://www.debian.org.tw/index.php/PageCache_writeback" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.debian.org.tw/index.php/PageCache_writeback</a>)</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">proc_root_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案fs/proc/root.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
初始化 proc 檔案系統.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">check_bugs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案arch/arm/mm/fault-armv.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
check_bugs 會被define為 “check_writebuffer_bugs”,用以Check處理器平台Bugs的狀況.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在筆者所編譯的ARM環境中, check_writebuffer_bugs會透過vmap(實作在mm/vmalloc.c中),把同一個屬性為Bufferable的Page對應到兩個Linux Kernel虛擬記憶體中,再透過設計好 check_writebuffer函式,對剛才得到的兩個虛擬記憶體位置寫入資料,並在每個動作後,加入ARM DSB(Data Synchronization Barrier)指令,透過 “dsb sy” 同步Cache, Branch Predictor 與TLB內容.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果說,兩個對應到同一個實體記憶體的Bufferable虛擬記憶體寫入動作,最後內容不是一致的,這個ARM平台就可能有Write Buffer Coherency的Bug存在.</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="147">rest_init</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="499">實作在檔案init/main.c中,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">這是start_kernel</span></strong><strong><span style="text-decoration-line: underline;">最後的函式. </span></strong><strong><span style="text-decoration-line: underline;">有關這函式與後續kernel_init</span></strong><strong><span style="text-decoration-line: underline;">的介紹,</span></strong><strong><span style="text-decoration-line: underline;">會放在下一次的文章中.</span></strong></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel是一個經過長期累積的知識庫,並且由於眾人的幫助,Linux Kernel也支援最新的ARMv7指令集,並支援處理器Bugs確認的機制,對於一般開發者而言,只要善用Linux Kernel所提供的成果,便可以在最快的時間內,進行核心的移植與系統的調教.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
隨著多核心SMP架構在Intel與ARM平台的普及,我們可以看到Linux對於SMP 多核心原生架構的支援也非常的充分,相關的核心模塊都會考慮到多核心並取得處理器的數量,做出對應資料結構與行為的因應,對於開發者在新架構的適應來說,可以很幸福的基於這些成果來發展. 尤其,隨著Android的普及,以及在Android 3.0 Framework對於多核心的初步支援,我們可以預期,未來考量到省電與效能的平衡,多核心肯定會是消費性產品的主流,對有至於從事消費性產品開發的人而言, 這部份的知識建立,也是當務之急.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com1tag:blogger.com,1999:blog-1668810802505961314.post-44747238696716818512017-06-03T08:38:00.003-07:002017-06-03T08:38:48.898-07:00Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(1) Boot-Rom與UBoot.<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android 筆記-Linux Kernel SMP (Symmetric Multi-Processors) 開機流程解析 Part(1) Boot-Rom與UBoot.</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Android </span>筆記<span style="font-family: "Times New Roman", serif;">-Linux Kernel SMP (Symmetric Multi-Processors) </span>開機流程解析 <span style="font-family: "Times New Roman", serif;">Part(1) Boot-Rom</span>與<span style="font-family: "Times New Roman", serif;">UBoot.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "Times New Roman", serif;">hlchou@mail2000.com.tw</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "Times New Roman", serif;">by loda.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文主要針對<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>支援<span style="font-family: "Times New Roman", serif;">ARM MPCore</span>架構下所需的多核心開機流程作一個介紹<span style="font-family: "Times New Roman", serif;">,</span>所涉及的內容會以筆者認為值得進一步說明的內容為主<span style="font-family: "Times New Roman", serif;">,</span>從目前市面上的產品來分析<span style="font-family: "Times New Roman", serif;">,</span>雖然都是針對<span style="font-family: "Times New Roman", serif;">ARM MPCore</span>的產品<span style="font-family: "Times New Roman", serif;">,</span>然而這些流程上都還是有所出入<span style="font-family: "Times New Roman", serif;">,</span>也因此<span style="font-family: "Times New Roman", serif;">,</span>本文的內容主要是提供實作上的介紹與例子<span style="font-family: "Times New Roman", serif;">,</span>實際的產品開發<span style="font-family: "Times New Roman", serif;">,</span>請以所參與的<span style="font-family: "Times New Roman", serif;">MPCore SoC</span>計畫為主<span style="font-family: "Times New Roman", serif;">. </span>其實只要能掌握好<span style="font-family: "Times New Roman", serif;">ARM</span>處理器的行為<span style="font-family: "Times New Roman", serif;">,</span>有關<span style="font-family: "Times New Roman", serif;">MPCore</span>與<span style="font-family: "Times New Roman", serif;">Linux Kernel SMP</span>的支援相信都是能夠游刃有餘的<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於筆者時間關係<span style="font-family: "Times New Roman", serif;">,</span>本文會分段刊登<span style="font-family: "Times New Roman", serif;">,</span>還請見諒<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Linux Kernel</strong></span></span><span style="font-size: small;"><strong>對多核心的支援</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Linux</span>從<span style="font-family: "Times New Roman", serif;">Kernel 2.0</span>開始<span style="font-family: "Times New Roman", serif;">,</span>就已經加入對<span style="font-family: "Times New Roman", serif;">SMP (Symmetric Multi Processors)</span>的支援<span style="font-family: "Times New Roman", serif;">,Linux Kernel</span>會以<span style="font-family: "Times New Roman", serif;">Process</span>或是<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>為單位來對排程<span style="font-family: "Times New Roman", serif;">,</span>也就是說<span style="font-family: "Times New Roman", serif;">Process</span>或<span style="font-family: "Times New Roman", serif;">Kernel Thread</span>都有機會會被安排在一個處理器上運作<span style="font-family: "Times New Roman", serif;">.</span>到了<span style="font-family: "Times New Roman", serif;">Kernel 2.2</span>時<span style="font-family: "Times New Roman", serif;">,Linux SMP</span>已經支援<span style="font-family: "Times New Roman", serif;">UltraSparc, SparcServer, Alpha </span>與 <span style="font-family: "Times New Roman", serif;">PowerPC</span>相關處理器<span style="font-family: "Times New Roman", serif;">. Linux</span>上的<span style="font-family: "Times New Roman", serif;">Thread</span>是透過 <span style="font-family: "Times New Roman", serif;">clone</span>的方式產生的<span style="font-family: "Times New Roman", serif;">,</span>也就是說<span style="font-family: "Times New Roman", serif;">Thread</span>會共享父<span style="font-family: "Times New Roman", serif;">Process</span>的資源與記憶體空間<span style="font-family: "Times New Roman", serif;">.</span>對多核心處理器而言<span style="font-family: "Times New Roman", serif;">,</span>這些<span style="font-family: "Times New Roman", serif;">Thread</span>也會有自己的<span style="font-family: "Times New Roman", serif;">Process Id</span>與<span style="font-family: "Times New Roman", serif;">Priority,</span>並且會一同參與多核心處理器的多工排程<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在<span style="font-family: "Times New Roman", serif;">make mnuconfig</span>選項中<span style="font-family: "Times New Roman", serif;">,</span>選擇 <span style="font-family: "Times New Roman", serif;">Processor type and features —>Symmetric multi-processing support </span>就可以開啟<span style="font-family: "Times New Roman", serif;">Kernel</span>對於多核心的支援<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>軟體識別目前所在的處理器</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行時期<span style="font-family: "Times New Roman", serif;">,</span>軟體可以透過 <span style="font-family: "Times New Roman", serif;">CPU ID Register</span>知道目前是<span style="font-family: "Times New Roman", serif;">MPCore</span>中哪個處理器執行該程式碼<span style="font-family: "Times New Roman", serif;">,CPU Id</span>儲存在<span style="font-family: "Times New Roman", serif;">CP15 c0</span>中<span style="font-family: "Times New Roman", serif;">,</span>長度為<span style="font-family: "Times New Roman", serif;">32bits,</span>只能在特權等級<span style="font-family: "Times New Roman", serif;">(</span>也就是<span style="font-family: "Times New Roman", serif;">SVC Mode</span>下<span style="font-family: "Times New Roman", serif;">)</span>被讀取<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
讀取的範例如下程式碼所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p15,0,<Rd>,c0,c0,5; returns CPU ID register</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 811px;"><colgroup><col width="14"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="16"></col><col width="14"></col><col width="15"></col><col width="15"></col><col width="17"></col><col width="14"></col><col width="15"></col><col width="15"></col><col width="22"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>31</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>30</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>29</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>28</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>27</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>26</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>25</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>24</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>23</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>22</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>21</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>20</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>19</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>18</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>17</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>16</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>15</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>14</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>13</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>12</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>11</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>10</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>9</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="16"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>8</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>7</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>6</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>5</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>4</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>3</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>2</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="22"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></td></tr>
<tr valign="TOP"><td colspan="20" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="491"><span style="font-family: "Times New Roman", serif;"><strong>SBZ</strong></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"><span style="font-family: "Times New Roman", serif;"><strong>Cluster ID</strong></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="91"><span style="font-family: "Times New Roman", serif;"><strong>SBZ</strong></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="96"><span style="font-family: "Times New Roman", serif;"><strong>CPU ID</strong></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明如下<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,Cluster ID: </span>用以支援 <span style="font-family: "Times New Roman", serif;">Multi-MPCore</span>架構下的<span style="font-family: "Times New Roman", serif;">Cluster</span>識別之用 <span style="font-family: "Times New Roman", serif;">(The Cluster ID field value is set by the CLUSTERID configuration pins.)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,CPU ID: </span>視處理器的個數<span style="font-family: "Times New Roman", serif;">,</span>例如四個處理器<span style="font-family: "Times New Roman", serif;">ID</span>依序為 <span style="font-family: "Times New Roman", serif;">0x00,0x01,0x02</span>與<span style="font-family: "Times New Roman", serif;">0x03</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>多核心的開機</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong></strong></span></span><span style="font-size: x-small;">一般我們稱為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Boot Loader</span></span><span style="font-size: x-small;">就是在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">OS</span></span><span style="font-size: x-small;">前處理載入流程的動作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">通常也稱為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Boot Code</span></span><span style="font-size: x-small;">或是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Boot Monitor (ARM</span></span><span style="font-size: x-small;">本身所出的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Boot Loader),</span></span><span style="font-size: x-small;">由於並非所有的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Flash</span></span><span style="font-size: x-small;">裝置都支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">XIP (Execute-in-Place),</span></span><span style="font-size: x-small;">因此針對像是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NAND</span></span><span style="font-size: x-small;">或是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">SD/eMMC</span></span><span style="font-size: x-small;">這類裝置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會需要有在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">SoC BootRom</span></span><span style="font-size: x-small;">上的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Boot Code</span></span><span style="font-size: x-small;">支援對於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Block</span></span><span style="font-size: x-small;">裝置的讀取</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">以便順利載入第二階段的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">BootLoader,</span></span><span style="font-size: x-small;">讓後續的流程如規劃進行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">筆者在整理本文時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">有看到這篇文章</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">“Booting ARM Linux SMP on MPCore” (in </span><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://geek43.springnote.com/pages/7909760?print=1" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-size: x-small;">http://geek43.springnote.com/pages/7909760?print=1</span></a></span></span><span style="font-size: x-small;"> </span></span><span style="font-size: x-small;">或 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">http://www.linux-arm.org/pub/LinuxPlatform/RealViewLink/Booting_ARM_Linux_SMP_on_MPCore.doc),</span></span><span style="font-size: x-small;">對於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Linux Kernel SMP</span></span><span style="font-size: x-small;">有興趣的讀者除了本文外</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">建議也可以參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">由於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NAND Flash</span></span><span style="font-size: x-small;">需要處理 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Bad Block,</span></span><span style="font-size: x-small;">且軟體在作業系統檔案系統本身</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">針對</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NAND Flash</span></span><span style="font-size: x-small;">裝置也需要支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ECC,FTL(Flash Translation Layer)</span></span><span style="font-size: x-small;">與 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Wear-Leveling</span></span><span style="font-size: x-small;">機制</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">藉以避免在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NAND Flash</span></span><span style="font-size: x-small;">上的正確性問題</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">也因此</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">附帶上述演算法的硬體實現</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Controller</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">eMMC</span></span><span style="font-size: x-small;">也就被目前許多消費性產品所使用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">一般而言</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在低階的產品上</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NAND Flash</span></span><span style="font-size: x-small;">還是有價格上的優勢</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">而在大容量儲存媒體的消費性產品中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,eMMC</span></span><span style="font-size: x-small;">則會有較高的性價比</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>BootRom</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在<span style="font-family: "Times New Roman", serif;">MPCore</span>中<span style="font-family: "Times New Roman", serif;">,</span>每個<span style="font-family: "Times New Roman", serif;">ARM</span>的處理器一開始的記憶體位址都是<span style="font-family: "Times New Roman", serif;">0x00000000,</span>通常我們可以有兩種方式提供啟動程式碼的執行<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,NOR Flash</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,Boot Rom</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於單位儲存成本<span style="font-family: "Times New Roman", serif;">NOR Flash</span>較高<span style="font-family: "Times New Roman", serif;">,</span>因此在需要大儲存空間的產品上<span style="font-family: "Times New Roman", serif;">,</span>會選擇透過<span style="font-family: "Times New Roman", serif;">NAND Flash</span>儲存<span style="font-family: "Times New Roman", serif;">BootLoader</span>與作業系統<span style="font-family: "Times New Roman", serif;">,</span>因此為了讓系統可以順利的執行開機流程<span style="font-family: "Times New Roman", serif;">,</span>就會透過晶片上的<span style="font-family: "Times New Roman", serif;">Boot Rom</span>定位到位址<span style="font-family: "Times New Roman", serif;">0x00000000,</span>並在其中儲存支援<span style="font-family: "Times New Roman", serif;">MPCore</span>的程式碼<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在系統尚未啟動前<span style="font-family: "Times New Roman", serif;">,</span>只有<span style="font-family: "Times New Roman", serif;">RTC Clock</span>時脈為<span style="font-family: "Times New Roman", serif;">32.768KHz,</span>而在系統啟動時<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">PLL(Phase Locked Loop)</span>起震前<span style="font-family: "Times New Roman", serif;">,</span>只有<span style="font-family: "Times New Roman", serif;">Boot Rom</span>或是<span style="font-family: "Times New Roman", serif;">NOR Flash</span>這類裝置可以用來執行處理器的指令集<span style="font-family: "Times New Roman", serif;">,</span>因此在<span style="font-family: "Times New Roman", serif;">Boot Rom</span>或<span style="font-family: "Times New Roman", serif;">NOR Flash</span>中的程式碼<span style="font-family: "Times New Roman", serif;">,</span>就必須讓系統的<span style="font-family: "Times New Roman", serif;">PLL</span>正常<span style="font-family: "Times New Roman", serif;">,</span>以便可以達到最佳的處理器與平台效能<span style="font-family: "Times New Roman", serif;">,</span>在系統初始化外部記憶體前<span style="font-family: "Times New Roman", serif;">,</span>所使用的<span style="font-family: "Times New Roman", serif;">Stack</span>或是可寫入的記憶體區塊就必須是 <span style="font-family: "Times New Roman", serif;">OnChip</span>的<span style="font-family: "Times New Roman", serif;">SRAM,</span>直到外部記憶體被初始化後<span style="font-family: "Times New Roman", serif;">,</span>才可以使用外部記憶體<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以支援<span style="font-family: "Times New Roman", serif;">NAND Boot</span>的行為來說<span style="font-family: "Times New Roman", serif;">,Boot Rom</span>會需要執行以下的行為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>讓<span style="font-family: "Times New Roman", serif;">CPU0</span>執行主要開機流程<span style="font-family: "Times New Roman", serif;">,</span>其它的處理器進入<span style="font-family: "Times New Roman", serif;">WFI. (</span>在啟動時<span style="font-family: "Times New Roman", serif;">,</span>每個處理器可以透過<span style="font-family: "Times New Roman", serif;">CPU ID</span>得知自己是否為<span style="font-family: "Times New Roman", serif;">CPU0,</span>如果不是<span style="font-family: "Times New Roman", serif;">,</span>就進入<span style="font-family: "Times New Roman", serif;">WFI</span>的程式碼中<span style="font-family: "Times New Roman", serif;">.)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,</span>初始化外部記憶體與執行系統的初始化</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>設定 <span style="font-family: "Times New Roman", serif;">Stack</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,</span>把<span style="font-family: "Times New Roman", serif;">BootRom</span>程式碼複製到外部記憶體中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">5,</span>重新<span style="font-family: "Times New Roman", serif;">Mapping </span>記憶體位置 <span style="font-family: "Times New Roman", serif;">(</span>把<span style="font-family: "Times New Roman", serif;">0x00000000</span>位址對應到外部記憶體 或 <span style="font-family: "Times New Roman", serif;">I-TCM</span>如果 <span style="font-family: "Times New Roman", serif;">0x00000000</span>位址要跑中斷表的話<span style="font-family: "Times New Roman", serif;">(or </span>中斷表對應到<span style="font-family: "Times New Roman", serif;">0xffff0000))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">6,</span>把第二階段的<span style="font-family: "Times New Roman", serif;">BootLoader</span>載入到外部記憶體中 <span style="font-family: "Times New Roman", serif;">or OnChip SRAM.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7,</span>執行第二階段的<span style="font-family: "Times New Roman", serif;">BootLoader</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
到這階段為止<span style="font-family: "Times New Roman", serif;">,</span>系統會維持在低速的運作中<span style="font-family: "Times New Roman", serif;">(</span>例如<span style="font-family: "Times New Roman", serif;">:PLL=19.2MHz)</span>或是直接初始化<span style="font-family: "Times New Roman", serif;">PLL</span>到最後的頻率<span style="font-family: "Times New Roman", serif;">(</span>視所實作的<span style="font-family: "Times New Roman", serif;">SoC</span>需求而定<span style="font-family: "Times New Roman", serif;">),</span>外部記憶體也會進行初始化<span style="font-family: "Times New Roman", serif;">(</span>包括要判斷記憶體的大小與初始化流程<span style="font-family: "Times New Roman", serif;">),</span>讓第二階段的<span style="font-family: "Times New Roman", serif;">BootLoader</span>載入到記憶體後可以直接執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>U-Boot</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在<span style="font-family: "Times New Roman", serif;">NAND</span>或<span style="font-family: "Times New Roman", serif;">eMMC</span>的方案中<span style="font-family: "Times New Roman", serif;">,UBoot</span>通常會被<span style="font-family: "Times New Roman", serif;">Linux</span>的產品定義為第二階段的<span style="font-family: "Times New Roman", serif;">BootLoader (</span>也因為它所支援的互動命令介面彈性<span style="font-family: "Times New Roman", serif;">.).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先<span style="font-family: "Times New Roman", serif;">,</span>各位取得<span style="font-family: "Times New Roman", serif;">u-boot-2011.06-rc3</span>版本的<span style="font-family: "Times New Roman", serif;">UBoot</span>程式碼後<span style="font-family: "Times New Roman", serif;">,</span>會看到包括如下的<span style="font-family: "Times New Roman", serif;">Source Code</span>目錄<span style="font-family: "Times New Roman", serif;">,</span>簡要說明如下</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 807px;"><colgroup><col width="203"></col><col width="581"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203">目錄</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">說明</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">api</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">提供包括<span style="font-family: "Times New Roman", serif;">Device Read/Write/Enum, Environment Get/Set/Enum,SysCall,Timers,Storage</span>相關的介面<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">common</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">主要為跟硬體與系統架構無關的檔案<span style="font-family: "Times New Roman", serif;">,</span>包括透過<span style="font-family: "Times New Roman", serif;">Console</span>控制命令處理與環境變數配置<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">tools</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">提供包括<span style="font-family: "Times New Roman", serif;">GDB,Flash Updater..etc</span>工具<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">lib</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">提供<span style="font-family: "Times New Roman", serif;">CRC,BZLib,MD5,SHA1,</span>軟體除法實作<span style="font-family: "Times New Roman", serif;">…etc</span>函式庫</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">arch</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">為依據不同對應處理器架構與型號相關的底層程式碼<span style="font-family: "Times New Roman", serif;">,</span>包括處理器<span style="font-family: "Times New Roman", serif;">arm,avr32,blackfin,m68k,microblaze,mips,nios2,powerpc,sh,sparc</span>與<span style="font-family: "Times New Roman", serif;">x86.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以<span style="font-family: "Times New Roman", serif;">arch/arm/cpu</span>配置為例<span style="font-family: "Times New Roman", serif;">,Cortex</span>處理器的支援是在<span style="font-family: "Times New Roman", serif;">armv7</span>目錄下<span style="font-family: "Times New Roman", serif;">,</span>目前支援的<span style="font-family: "Times New Roman", serif;">Cortex</span>處理器產品包括 <span style="font-family: "Times New Roman", serif;">TI</span>的 <span style="font-family: "Times New Roman", serif;">omap3/omap4,Samsung</span>的 <span style="font-family: "Times New Roman", serif;">s5pc1xx/s5pc2xx,Freescale</span>的 <span style="font-family: "Times New Roman", serif;">mx5,ST-Ericsson</span>的 <span style="font-family: "Times New Roman", serif;">u8500 </span>與 <span style="font-family: "Times New Roman", serif;">Nvidia</span>的 <span style="font-family: "Times New Roman", serif;">tegra2 ,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其他有關的檔案包括</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">u-boot.lds=></span>用以描述<span style="font-family: "Times New Roman", serif;">u-boot binary</span>檔案的配置<span style="font-family: "Times New Roman", serif;">,</span>以筆者手中的版本來說<span style="font-family: "Times New Roman", serif;">,</span>在啟動<span style="font-family: "Times New Roman", serif;">u-boot</span>時<span style="font-family: "Times New Roman", serif;">,</span>最先執行的為<span style="font-family: "Times New Roman", serif;">arch/arm/cpu/armv7/start.o</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對應到<span style="font-family: "Times New Roman", serif;">Source Code</span>為 <span style="font-family: "Times New Roman", serif;">arch/arm/cpu/armv7/start.S,</span>我們可以透過這個檔案為起點<span style="font-family: "Times New Roman", serif;">,</span>來追蹤<span style="font-family: "Times New Roman", serif;">u-boot</span>在<span style="font-family: "Times New Roman", serif;">Cortex</span>下的啟動流程<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">cpu.c:</span>支援在正式進入<span style="font-family: "Times New Roman", serif;">Linux</span>前<span style="font-family: "Times New Roman", serif;">,</span>對<span style="font-family: "Times New Roman", serif;">L1/L2 Cache</span>的<span style="font-family: "Times New Roman", serif;">Flush</span>與啟用<span style="font-family: "Times New Roman", serif;">.</span>以<span style="font-family: "Times New Roman", serif;">Nvidia Tegra2</span>處理器產品為例<span style="font-family: "Times New Roman", serif;">,</span>有關的檔案還有</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ap20.c:</span>初始化 <span style="font-family: "Times New Roman", serif;">Cache,UART,PLL,Clock,CoreSight,Snoopy Control Unit(Cache Coherency Bus),</span>啟動<span style="font-family: "Times New Roman", serif;">JTAG,</span>暫停<span style="font-family: "Times New Roman", serif;">CPU1</span>的<span style="font-family: "Times New Roman", serif;">Clock, PMU (Power Management Unit)</span>控制<span style="font-family: "Times New Roman", serif;">,</span>把<span style="font-family: "Times New Roman", serif;">CPU</span>進入<span style="font-family: "Times New Roman", serif;">Reset (Tegra2</span>為雙核<span style="font-family: "Times New Roman", serif;">),</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">board.c: </span>確認在板子上的記憶體顆粒大小<span style="font-family: "Times New Roman", serif;">,</span>支援<span style="font-family: "Times New Roman", serif;">256,512</span>與<span style="font-family: "Times New Roman", serif;">1GB RAM Size,</span>初始化<span style="font-family: "Times New Roman", serif;">DRAM,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">lowlevel_init.S:</span>初始化<span style="font-family: "Times New Roman", serif;">I/D-Cache,SMP Mode,</span>支援 <span style="font-family: "Times New Roman", serif;">CPU/AVP Mode</span>的冷開機<span style="font-family: "Times New Roman", serif;">(Cold Boot).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">timer.c:</span>支援 <span style="font-family: "Times New Roman", serif;">Timer</span>與<span style="font-family: "Times New Roman", serif;">udelay</span>相關函式<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">board</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">主要為現有支援的板子<span style="font-family: "Times New Roman", serif;">,</span>包括外部記憶體位址<span style="font-family: "Times New Roman", serif;">,</span>硬體配置與<span style="font-family: "Times New Roman", serif;">u-boot.lds</span>都會跟這目錄下對應的開發版硬體有關<span style="font-family: "Times New Roman", serif;">,</span>由於支援的板子數量很多<span style="font-family: "Times New Roman", serif;">,</span>以<span style="font-family: "Times New Roman", serif;">Nvidia</span>為例<span style="font-family: "Times New Roman", serif;">,</span>共支援兩款板子<span style="font-family: "Times New Roman", serif;">harmony</span>與<span style="font-family: "Times New Roman", serif;">seaboard</span></td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">drivers</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581"><span style="font-family: "Times New Roman", serif;">UBoot</span>支援豐富的<span style="font-family: "Times New Roman", serif;">Driver</span>周邊<span style="font-family: "Times New Roman", serif;">,</span>並且也從<span style="font-family: "Times New Roman", serif;">Linux Driver</span>中擷取有關的資源<span style="font-family: "Times New Roman", serif;">,</span>目前共支援以下<span style="font-family: "Times New Roman", serif;">Drvers</span>種類<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(</span>坦白說我覺得<span style="font-family: "Times New Roman", serif;">UBoot</span>做的有點太強大了<span style="font-family: "Times New Roman", serif;">,</span>除了沒有多工排程<span style="font-family: "Times New Roman", serif;">,</span>完整的<span style="font-family: "Times New Roman", serif;">TCPIP,MM</span>外<span style="font-family: "Times New Roman", serif;">,</span>其他功能都算是頗有規模了<span style="font-family: "Times New Roman", serif;">)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">bios_emulator : </span>可用以模擬<span style="font-family: "Times New Roman", serif;">x86 Real-Mode BIOS.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">fpga : </span>用以支援 <span style="font-family: "Times New Roman", serif;">Xilinx,Altera,Virtex, Spartan, Stratix, Cyclon, Lattice</span>的 <span style="font-family: "Times New Roman", serif;">FPGA</span>開發環境<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">i2c : </span>這在有包括 <span style="font-family: "Times New Roman", serif;">i2c</span>的共用程式碼<span style="font-family: "Times New Roman", serif;">,</span>以及針對每個平台<span style="font-family: "Times New Roman", serif;">,</span>例如 <span style="font-family: "Times New Roman", serif;">TI OMAP,Samsung,ST-Erricsson u8500..etc</span>系列的<span style="font-family: "Times New Roman", serif;">I2C</span>控制介面</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mmc : </span>用以支援<span style="font-family: "Times New Roman", serif;">MMC/SD</span>這類記憶卡周邊的控制介面<span style="font-family: "Times New Roman", serif;">,</span>並包括<span style="font-family: "Times New Roman", serif;">ARM PL180,Atmel,PXA,OMAP,MX</span>相關處理器的平台<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">pci : </span>用以支援<span style="font-family: "Times New Roman", serif;">PCI Bus,</span>包括<span style="font-family: "Times New Roman", serif;">IXP,SH,Freescale,Tundra ..etc</span>相關的<span style="font-family: "Times New Roman", serif;">PCI</span>控制介面</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">qe : QE </span>全名為 <span style="font-family: "Times New Roman", serif;">QUICCQUICC(Quad Integrated Communications Controller) Engine </span>是一個<span style="font-family: "Times New Roman", serif;">Freescale </span>在<span style="font-family: "Times New Roman", serif;">PowerPC</span>下的介面<span style="font-family: "Times New Roman", serif;">,QE</span>設計目的在於讓<span style="font-family: "Times New Roman", serif;">CPU</span>或<span style="font-family: "Times New Roman", serif;">DSP,</span>不需要去處理通訊端的封包<span style="font-family: "Times New Roman", serif;">,</span>透過<span style="font-family: "Times New Roman", serif;">RISC</span>處理器的可程式化通訊協定加速引擎<span style="font-family: "Times New Roman", serif;">,</span>只要修改微程式碼就能支援不同的通訊協定及功能<span style="font-family: "Times New Roman", serif;">(</span>包括<span style="font-family: "Times New Roman", serif;">IP/Ethernet,ATM,QoS).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">spi : </span>用以支援 <span style="font-family: "Times New Roman", serif;">SPI</span>介面<span style="font-family: "Times New Roman", serif;">,</span>包括 <span style="font-family: "Times New Roman", serif;">Altera,Atmel,MX,OMAP,SH..etc.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">video : </span>用以支援<span style="font-family: "Times New Roman", serif;">Display</span>的介面<span style="font-family: "Times New Roman", serif;">,</span>可在<span style="font-family: "Times New Roman", serif;">Uboot</span>啟動過程中顯示圖像在<span style="font-family: "Times New Roman", serif;">LCM/LCD</span>上<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">block : </span>用以支援 <span style="font-family: "Times New Roman", serif;">SCSI/MGDISK/IDE/SATA..etc</span>介面的<span style="font-family: "Times New Roman", serif;">Block</span>儲存媒體</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">gpio : </span>用以支援<span style="font-family: "Times New Roman", serif;">GPIO</span>介面<span style="font-family: "Times New Roman", serif;">.</span>包括會根據平台的差異<span style="font-family: "Times New Roman", serif;">,</span>有各自的<span style="font-family: "Times New Roman", serif;">Base Address</span>與行為<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">input : </span>可用以支援<span style="font-family: "Times New Roman", serif;">Intel 8042/PS2</span>介面的<span style="font-family: "Times New Roman", serif;">Keyboard</span>與<span style="font-family: "Times New Roman", serif;">Mouse,</span>在筆者拿到的這版<span style="font-family: "Times New Roman", serif;">Code</span>中<span style="font-family: "Times New Roman", serif;">(u-boot-2011.06-rc3),Mouse</span>的部份是被<span style="font-family: "Times New Roman", serif;">Ignore</span>的<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mtd : </span>為<span style="font-family: "Times New Roman", serif;">Memory Technology Device</span>的介面<span style="font-family: "Times New Roman", serif;">,</span>可用以支援包括<span style="font-family: "Times New Roman", serif;">NAND/OneNAND/SPI/Jedec/CFI(Common Flash Interface)</span>介面的<span style="font-family: "Times New Roman", serif;">Flash</span>裝置<span style="font-family: "Times New Roman", serif;">,</span>讓上層不需要去處理不同儲存媒體的差異<span style="font-family: "Times New Roman", serif;">,</span>只要統一透過<span style="font-family: "Times New Roman", serif;">MTD</span>介面操作即可<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">pcmcia : </span>用以支援<span style="font-family: "Times New Roman", serif;">PCMCIA</span>介面</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">rtc : </span>為 <span style="font-family: "Times New Roman", serif;">Real-Time Clock Controller </span>的驅動</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">twserial : </span>為一個<span style="font-family: "Times New Roman", serif;">Serial</span>控制介面<span style="font-family: "Times New Roman", serif;">,</span>例如 <span style="font-family: "Times New Roman", serif;">rtc4543 </span>就須透過這個<span style="font-family: "Times New Roman", serif;">Serial</span>介面進行<span style="font-family: "Times New Roman", serif;">Read/Write</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">watchdog : </span>支援 <span style="font-family: "Times New Roman", serif;">WatchDog (</span>如果你認為所在平台需要的話<span style="font-family: "Times New Roman", serif;">),</span>目前有<span style="font-family: "Times New Roman", serif;">FTWDT010</span>與<span style="font-family: "Times New Roman", serif;">Atmel AT91SAM9x</span>上的實作</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">dma : </span>用以支援不同平台的<span style="font-family: "Times New Roman", serif;">Direct Memory Access Controller.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">hwmon : </span>主要支援硬體的感知器<span style="font-family: "Times New Roman", serif;">,</span>像是<span style="font-family: "Times New Roman", serif;">Thermometer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">misc : </span>用以支援包括<span style="font-family: "Times New Roman", serif;">LED Service Light</span>或<span style="font-family: "Times New Roman", serif;">PMIC..etc</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">net :</span>用以支援包括<span style="font-family: "Times New Roman", serif;">RealTek</span>在內的各類網卡<span style="font-family: "Times New Roman", serif;">Driver</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">power :</span>用以支援包括<span style="font-family: "Times New Roman", serif;">Faraday,TI</span>平台的電源控制</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">serial :</span>用以支援各類<span style="font-family: "Times New Roman", serif;">UART Serial Port.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">usb : </span>用以支援 <span style="font-family: "Times New Roman", serif;">USB Ethernet,Host/Gadget Controller,</span>提供包括<span style="font-family: "Times New Roman", serif;">OMAP,BlackFin,..etc</span>相關平台<span style="font-family: "Times New Roman", serif;">..etc</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">post</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">全名為 <span style="font-family: "Times New Roman", serif;">power on self test,</span>其中包括處理器<span style="font-family: "Times New Roman", serif;">,</span>驅動與對應的<span style="font-family: "Times New Roman", serif;">Board</span>形式</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">net</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">支援<span style="font-family: "Times New Roman", serif;">NFS,DNS,TFTP,SNTP..etc</span>網路協定</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">fs</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">支援<span style="font-family: "Times New Roman", serif;">CramFS,Ext2,FAT,FDOS,JFFS2,ReiserFS,UbiFS,Yaffs2</span>檔案系統</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">disk</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">主要為支援<span style="font-family: "Times New Roman", serif;">IDE/SCSI/SATA/MGDISK/USB DISK/MMC/SD Card</span>的儲存媒體裝置<span style="font-family: "Times New Roman", serif;">,</span>讓上層可以透過<span style="font-family: "Times New Roman", serif;">DISK</span>裝置例如以<span style="font-family: "Times New Roman", serif;">LBA Mode</span>去存取相關的<span style="font-family: "Times New Roman", serif;">DISK Sector,</span>包括<span style="font-family: "Times New Roman", serif;">DISK</span>裝置的<span style="font-family: "Times New Roman", serif;">Partition Table</span>讀取<span style="font-family: "Times New Roman", serif;">,</span>或是光碟裝置的<span style="font-family: "Times New Roman", serif;">ISO</span>檔案<span style="font-family: "Times New Roman", serif;">,</span>都可以加以識別與存取<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;">mmc_spl</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">onenand_ipl</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nand_spl</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="581">用以支援存<span style="font-family: "Times New Roman", serif;">MMC/SD,OneNand</span>或是<span style="font-family: "Times New Roman", serif;">Nand Flash</span>把<span style="font-family: "Times New Roman", serif;">UBoot</span>載入到記憶體後<span style="font-family: "Times New Roman", serif;">,</span>執行<span style="font-family: "Times New Roman", serif;">UBoot</span>的環境<span style="font-family: "Times New Roman", serif;">,</span>一般而言<span style="font-family: "Times New Roman", serif;">,</span>我們可以選擇透過<span style="font-family: "Times New Roman", serif;">Boot Rom</span>直接載入<span style="font-family: "Times New Roman", serif;">UBoot,</span>或是透過<span style="font-family: "Times New Roman", serif;">NAND Flash</span>裝置最前面可以保證出廠時不是<span style="font-family: "Times New Roman", serif;">Bad Block</span>的區塊<span style="font-family: "Times New Roman", serif;">,</span>來存放載入<span style="font-family: "Times New Roman", serif;">UBoot</span>的前置載入程式<span style="font-family: "Times New Roman", serif;">.</span>可以透過在<span style="font-family: "Times New Roman", serif;">lds</span>檔案中加入<span style="font-family: "Times New Roman", serif;">ASSERT (</span>例如<span style="font-family: "Times New Roman", serif;">:nand_spl/board/freescale/mpc8313erdb/u-boot.lds),</span>確保<span style="font-family: "Times New Roman", serif;">NAND Flash Bootstrap不</span>會超過目標 <span style="font-family: "Times New Roman", serif;">NAND Flash</span>裝置第一個區塊的大小<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Uboot</span>的維護網站在 <span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://www.denx.de/wiki/U-Boot" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.denx.de/wiki/U-Boot</a></span></span> ,</span>有興趣的開發者<span style="font-family: "Times New Roman", serif;">,</span>可以自行參閱<span style="font-family: "Times New Roman", serif;">.</span>在<span style="font-family: "Times New Roman", serif;">Uboot</span>的<span style="font-family: "Times New Roman", serif;">Source Code</span>中<span style="font-family: "Times New Roman", serif;">,</span>根目錄的 <span style="font-family: "Times New Roman", serif;">config.mk</span>會根據所要編譯的處理器與開發版<span style="font-family: "Times New Roman", serif;">,</span>把對應目錄的<span style="font-family: "Times New Roman", serif;">config.mk</span>參考進來<span style="font-family: "Times New Roman", serif;">,</span>其中像是會定義在<span style="font-family: "Times New Roman", serif;">board</span>目錄下 <span style="font-family: "Times New Roman", serif;">config.mk</span>的<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_TEXT_BASE</span>參數<span style="font-family: "Times New Roman", serif;">,</span>會決定在<span style="font-family: "Times New Roman", serif;">Uboot</span>啟動時<span style="font-family: "Times New Roman", serif;">,</span>要把程式碼複製到哪一個記憶體位置中<span style="font-family: "Times New Roman", serif;">. </span>例如<span style="font-family: "Times New Roman", serif;">:TI OMAP</span>的<span style="font-family: "Times New Roman", serif;">2420h4</span>處理器<span style="font-family: "Times New Roman", serif;">,CONFIG_SYS_TEXT_BASE </span>為<span style="font-family: "Times New Roman", serif;">0x80e80000 ,</span>定義在<span style="font-family: "Times New Roman", serif;">board</span>目錄下的檔案<span style="font-family: "Times New Roman", serif;">board/ti/omap2420h4/config.mk</span>中<span style="font-family: "Times New Roman", serif;">.</span>不過也有另一種寫法<span style="font-family: "Times New Roman", serif;">,</span>例如<span style="font-family: "Times New Roman", serif;">Nvidia Tegra2</span>的<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_TEXT_BASE</span>為<span style="font-family: "Times New Roman", serif;">0x00E08000,</span>則是定義在檔案”<span style="font-family: "Times New Roman", serif;">include/configs/tegra2-common.h”</span>中<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Uboot</span>支援多種 <span style="font-family: "Times New Roman", serif;">OS</span>的開機<span style="font-family: "Times New Roman", serif;">, </span>可以參考檔案<span style="font-family: "Times New Roman", serif;">common/cmd_bootm.c ,Uboot</span>支援包括<span style="font-family: "Times New Roman", serif;">Linux,NetBSD,LYNXKDI,RTEMS,OSE,VxWork,QnxElf,INTEGRITY</span>多種<span style="font-family: "Times New Roman", serif;">OS</span>起始<span style="font-family: "Times New Roman", serif;">,</span>並支援包括<span style="font-family: "Times New Roman", serif;">ARM,AVR32,BlackFin,i386,M68K,MicroBlaze,MIPS,NIOS2,PPC,SH,Spare</span>多種處理器<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在最終的產品時<span style="font-family: "Times New Roman", serif;">,</span>可以透過設定 <span style="font-family: "Times New Roman", serif;">CONFIG_BOOTDELAY=0,</span>讓啟動過程不用等待<span style="font-family: "Times New Roman", serif;">,</span>以及設定<span style="font-family: "Times New Roman", serif;">CONFIG_BOOTCOMMAND = “tftp 8000000 pImage.metrobox;bootm 8000000” (</span>等待來自<span style="font-family: "Times New Roman", serif;">TFTP</span>的<span style="font-family: "Times New Roman", serif;">Image,</span>並從記憶體開機<span style="font-family: "Times New Roman", serif;">) </span>或 <span style="font-family: "Times New Roman", serif;">CONFIG_BOOTCOMMAND=”nand read 0x21000000 0xa0000 0x200000; bootm” (</span>讀取來自<span style="font-family: "Times New Roman", serif;">NAND Flash</span>的<span style="font-family: "Times New Roman", serif;">Image,</span>並從記憶體開機<span style="font-family: "Times New Roman", serif;">),</span>如此只要在<span style="font-family: "Times New Roman", serif;">UBoot</span>啟動時<span style="font-family: "Times New Roman", serif;">,</span>沒有在<span style="font-family: "Times New Roman", serif;">Console</span>輸入<span style="font-family: "Times New Roman", serif;">UBoot </span>命令<span style="font-family: "Times New Roman", serif;">(</span>等待<span style="font-family: "Times New Roman", serif;"><= CONFIG_BOOTDELAY</span>的時間<span style="font-family: "Times New Roman", serif;">),</span>就會採用上述預設的命令<span style="font-family: "Times New Roman", serif;">,</span>執行<span style="font-family: "Times New Roman", serif;">CONFIG_BOOTCOMMAND</span>的內容<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">CONFIG_BOOTDELAY</span>設定的單位為秒<span style="font-family: "Times New Roman", serif;">,</span>也就是說在啟動時會等待所設定的秒數<span style="font-family: "Times New Roman", serif;">,</span>並且會在函式<span style="font-family: "Times New Roman", serif;">abortboot</span>中每秒確認<span style="font-family: "Times New Roman", serif;">100</span>次使用者是否有透過<span style="font-family: "Times New Roman", serif;">Console</span>按鍵<span style="font-family: "Times New Roman", serif;">,</span>若有就會由函式<span style="font-family: "Times New Roman", serif;">abortboot</span>傳回<span style="font-family: "Times New Roman", serif;">1 (</span>也就是<span style="font-family: "Times New Roman", serif;">abort =1),</span>此時就會進入互動的介面而不會往後執行<span style="font-family: "Times New Roman", serif;">Linux Kernel Booting</span>的流程<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會透過環境變數<span style="font-family: "Times New Roman", serif;">“bootdelay”</span>取得<span style="font-family: "Times New Roman", serif;">CONFIG_BOOTDELAY</span>設定的值<span style="font-family: "Times New Roman", serif;">,</span>如果系統等待<span style="font-family: "Times New Roman", serif;">CONFIG_BOOTDELAY</span>秒後沒有進入互動介面<span style="font-family: "Times New Roman", serif;">,</span>就會取得環境變數<span style="font-family: "Times New Roman", serif;">“bootcmd”,</span>然後呼叫<span style="font-family: "Times New Roman", serif;">parse_string_outer</span>執行<span style="font-family: "Times New Roman", serif;">CONFIG_BOOTCOMMAND</span>的命令內容<span style="font-family: "Times New Roman", serif;">. (</span>有設定<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_HUSH_PARSER</span>就會呼叫<span style="font-family: "Times New Roman", serif;">common/hush.c</span>中的<span style="font-family: "Times New Roman", serif;">Hush Parser,</span>支援比較有彈性的語法<span style="font-family: "Times New Roman", serif;">,</span>包括<span style="font-family: "Times New Roman", serif;">“if…then…else…fi”,”&&”</span>或<span style="font-family: "Times New Roman", serif;">“||”,</span>反之就會呼叫函式<span style="font-family: "Times New Roman", serif;">run_command.)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後透過呼叫<span style="font-family: "Times New Roman", serif;">do_bootm_linux,</span>載入到記憶體後<span style="font-family: "Times New Roman", serif;">,x86(in arch/x86/lib/bootm.c)</span>會呼叫函式<span style="font-family: "Times New Roman", serif;">boot_zimage,ARM(in arch/arm/lib/bootm.c)</span>會呼叫函式<span style="font-family: "Times New Roman", serif;">kernel_entry ,</span>執行<span style="font-family: "Times New Roman", serif;">Linux Kernel .</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果是在使用<span style="font-family: "Times New Roman", serif;">NOR Flash</span>的嵌入式產品中<span style="font-family: "Times New Roman", serif;">,</span>也可以直接把<span style="font-family: "Times New Roman", serif;">UBoot</span>編譯到以<span style="font-family: "Times New Roman", serif;">0x00000000</span>記憶體位址為基礎的環境<span style="font-family: "Times New Roman", serif;">,</span>然後透過<span style="font-family: "Times New Roman", serif;">ARM</span>開機時<span style="font-family: "Times New Roman", serif;">,</span>直接執行<span style="font-family: "Times New Roman", serif;">,</span>並在執行過程中把<span style="font-family: "Times New Roman", serif;">Stack</span>與<span style="font-family: "Times New Roman", serif;">Heap</span>設定到外部或<span style="font-family: "Times New Roman", serif;">OnChip</span>記憶體中<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">common/main.c </span>中的<span style="font-family: "Times New Roman", serif;">main_loop</span>為<span style="font-family: "Times New Roman", serif;">UBoot</span>啟動後<span style="font-family: "Times New Roman", serif;">,</span>主要處理<span style="font-family: "Times New Roman", serif;">Console</span>端命令介面的函式<span style="font-family: "Times New Roman", serif;">,Uboot</span>可以透過把<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>載入到記憶體後<span style="font-family: "Times New Roman", serif;">,</span>在透過函式 <span style="font-family: "Times New Roman", serif;">do_bootm (“bootm – boot application image from image in memory”),</span>去執行該記憶體位址<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
先不考慮 <span style="font-family: "Times New Roman", serif;">Uboot </span>對<span style="font-family: "Times New Roman", serif;">NAND/MMC/OneNand</span>載入的實作<span style="font-family: "Times New Roman", serif;">,</span>我們以從<span style="font-family: "Times New Roman", serif;">BootRom</span>把<span style="font-family: "Times New Roman", serif;">UBoot</span>啟動的流程做分析並以<span style="font-family: "Times New Roman", serif;">Tegra2</span>平台為例<span style="font-family: "Times New Roman", serif;">,</span>首先我們看在連結時用的<span style="font-family: "Times New Roman", serif;">arch/arm/cpu/armv7/u-boot.lds</span>檔案<span style="font-family: "Times New Roman", serif;">,</span>內容如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">OUTPUT_FORMAT(“elf32-littlearm”, “elf32-littlearm”, “elf32-littlearm”)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">OUTPUT_ARCH(arm)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ENTRY(_start)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">SECTIONS</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">. = 0x00000000;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">. = ALIGN(4);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.text :</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">arch/arm/cpu/armv7/start.o (.text)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">*(.text)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">. = ALIGN(4);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">. = ALIGN(4);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.data : {</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">*(.data)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">. = ALIGN(4);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">. = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__u_boot_cmd_start = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.u_boot_cmd : { *(.u_boot_cmd) }</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__u_boot_cmd_end = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">. = ALIGN(4);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.rel.dyn : {</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__rel_dyn_start = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">*(.rel*)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__rel_dyn_end = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.dynsym : {</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__dynsym_start = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">*(.dynsym)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">_end = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.bss __rel_dyn_start (OVERLAY) : {</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__bss_start = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">*(.bss)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">. = ALIGN(4);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__bss_end__ = .;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/DISCARD/ : { *(.dynstr*) }</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/DISCARD/ : { *(.dynamic*) }</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/DISCARD/ : { *(.plt*) }</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/DISCARD/ : { *(.interp*) }</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/DISCARD/ : { *(.gnu*) }</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以看到在<span style="font-family: "Times New Roman", serif;">Link</span>時<span style="font-family: "Times New Roman", serif;">,</span>會把 <span style="font-family: "Times New Roman", serif;">arch/arm/cpu/armv7/start.o</span>放在<span style="font-family: "Times New Roman", serif;">TEXT</span>節區的頭<span style="font-family: "Times New Roman", serif;">,</span>以<span style="font-family: "Times New Roman", serif;">nvidia Tegra2 seaboard </span>組態為例來說明<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(in arch/arm/cpu/armv7/start.S)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.globl _start</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">_start: b reset</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr pc, _undefined_instruction</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr pc, _software_interrupt</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr pc, _prefetch_abort</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr pc, _data_abort</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr pc, _not_used</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr pc, _irq</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr pc, _fiq</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們以實際編譯出來的<span style="font-family: "Times New Roman", serif;">u-boot.bin</span>來跟著邏輯走一次<span style="font-family: "Times New Roman", serif;">,</span>以<span style="font-family: "Times New Roman", serif;">Nvidia Tegra2</span>來說<span style="font-family: "Times New Roman", serif;">,UBoot</span>會載入到記憶體<span style="font-family: "Times New Roman", serif;">0x00e08000</span>的位址開始執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">00e08000 <_start>:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08000: ea000014 b e08058 <reset></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08004: e59ff014 ldr pc, [pc, #20] ; e08020 <_undefined_instruction></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08008: e59ff014 ldr pc, [pc, #20] ; e08024 <_software_interrupt></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e0800c: e59ff014 ldr pc, [pc, #20] ; e08028 <_prefetch_abort></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08010: e59ff014 ldr pc, [pc, #20] ; e0802c <_data_abort></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08014: e59ff014 ldr pc, [pc, #20] ; e08030 <_not_used></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08018: e59ff014 ldr pc, [pc, #20] ; e08034 <_irq></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e0801c: e59ff014 ldr pc, [pc, #20] ; e08038 <_fiq></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">…</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
之後執行<span style="font-family: "Times New Roman", serif;">reset</span>函式<span style="font-family: "Times New Roman", serif;">,</span>並呼叫到檔案 <span style="font-family: "Times New Roman", serif;">arch/arm/lib/board.c</span>中的函式<span style="font-family: "Times New Roman", serif;">board_init_f,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">00e08058 <reset>:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08058: e10f0000 mrs r0, CPSR</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e0805c: e3c0001f bic r0, r0, #31 ; 0x1f</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08060: e38000d3 orr r0, r0, #211 ; 0xd3</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08064: e129f000 msr CPSR_fc, r0</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">00e08068 <call_board_init_f>:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08068: e59fd3d8 ldr sp, [pc, #984] ; e08448 <fiq+0x48></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e0806c: e3cdd007 bic sp, sp, #7 ; 0x7</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08070: e3a00000 mov r0, #0 ; 0x0</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">e08074: eb0002c1 bl e08b80 <board_init_f></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在函式<span style="font-family: "Times New Roman", serif;">board_init_f,</span>可以看到<span style="font-family: "Times New Roman", serif;">board</span>的啟動順序為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>配置<span style="font-family: "Times New Roman", serif;">Global Data “struct global_data”(</span>宣告在<span style="font-family: "Times New Roman", serif;">include/asm/global_data.h)</span>的內容<span style="font-family: "Times New Roman", serif;">(</span>包括<span style="font-family: "Times New Roman", serif;">,</span>記憶體大小<span style="font-family: "Times New Roman", serif;">,ISR Stack,UBoot</span>起始位置<span style="font-family: "Times New Roman", serif;">,Timer Clock..etc),</span>以<span style="font-family: "Times New Roman", serif;">Trgra2</span>為例<span style="font-family: "Times New Roman", serif;">,</span>會參考<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_INIT_SP_ADDR </span>把<span style="font-family: "Times New Roman", serif;">gd_t</span>配置在記憶體位置<span style="font-family: "Times New Roman", serif;">0x02bfff80,</span>並初始化為<span style="font-family: "Times New Roman", serif;">0 (CONFIG_SYS_INIT_SP_ADDR</span>定義在 <span style="font-family: "Times New Roman", serif;">include/configs/tegra2-common.h).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2, init_sequence </span>其中包括如下流程 <span style="font-family: "Times New Roman", serif;">(</span>按照順序<span style="font-family: "Times New Roman", serif;">,</span>只有紅色部分為一定要的實作<span style="font-family: "Times New Roman", serif;">,</span>其它為可透過<span style="font-family: "Times New Roman", serif;">Config</span>參數選擇的<span style="font-family: "Times New Roman", serif;">)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">a,arch_cpu_init</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">b,board_early_init_f</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>c,timer_init </strong></span>: </span>初始化<span style="font-family: "Times New Roman", serif;">Timer</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">d,get_clocks</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>e,env_init</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>f,init_baudrate</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>g,serial_init</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>h,console_init_f</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>I,display_banner,</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">j,print_cpuinfo</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">k,checkboard</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">l,init_func_i2c</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>m,dram_init </strong></span>: </span>包含設定<span style="font-family: "Times New Roman", serif;">DRAM Size</span>到<span style="font-family: "Times New Roman", serif;">Global Data</span>中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">n,arm_pci_init</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>之後包括設定 <span style="font-family: "Times New Roman", serif;">irq_sp (</span>給中斷用的<span style="font-family: "Times New Roman", serif;">Stack),</span>呼叫<span style="font-family: "Times New Roman", serif;">relocate_code,</span>設定新的<span style="font-family: "Times New Roman", serif;">Stack,</span>並把程式碼從原本所在的位置搬到外部記憶體從高位址開始<span style="font-family: "Times New Roman", serif;">,</span>加上<span style="font-family: "Times New Roman", serif;">FrameBuffer,TLB</span>與相關空間後<span style="font-family: "Times New Roman", serif;">,</span>預留一塊大小為 <span style="font-family: "Times New Roman", serif;">_bss_end_ofs (__bss_end__ – _start)</span>的空間<span style="font-family: "Times New Roman", serif;">,</span>然後在<span style="font-family: "Times New Roman", serif;">relocate_code</span>函式中複製過去<span style="font-family: "Times New Roman", serif;">. (BSS</span>為<span style="font-family: "Times New Roman", serif;">Uninitialized Data Section,</span>沒有給予初值的全域變數就會配置在這個<span style="font-family: "Times New Roman", serif;">Section.). Relocation Code</span>的流程如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinoaiNLykHdy0eJ_Xskjc9Dj52ogdM022cLsRnfPL_DswqvxEvaxaEVHmQbKymFx7M2iN7htSnypiZEo_G2hKSQmBIai1Ve35nz5AAF9usLeXrrQIzSPn4BsTxcwEaXIWWMHX9ZVrv7AU/s1600/LinuxKernelMultiProcessorBooting_html_10e7a640%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="482" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinoaiNLykHdy0eJ_Xskjc9Dj52ogdM022cLsRnfPL_DswqvxEvaxaEVHmQbKymFx7M2iN7htSnypiZEo_G2hKSQmBIai1Ve35nz5AAF9usLeXrrQIzSPn4BsTxcwEaXIWWMHX9ZVrv7AU/s1600/LinuxKernelMultiProcessorBooting_html_10e7a640%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,</span>而我們在編譯階段<span style="font-family: "Times New Roman", serif;">,</span>會把<span style="font-family: "Times New Roman", serif;">Text Base</span>以<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_TEXT_BASE</span>值來設定<span style="font-family: "Times New Roman", serif;">,</span>也就是說<span style="font-family: "Times New Roman", serif;">,</span>程式碼的執行<span style="font-family: "Times New Roman", serif;">Base Address</span>就會是以<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_TEXT_BASE</span>位址為主<span style="font-family: "Times New Roman", serif;">,</span>因此在執行程式碼的<span style="font-family: "Times New Roman", serif;">Relocation</span>後<span style="font-family: "Times New Roman", serif;">,</span>由於整個程式碼的基礎位址改變了<span style="font-family: "Times New Roman", serif;">,</span>就會需要把參考到的<span style="font-family: "Times New Roman", serif;">Symbol</span>相關位置根據新<span style="font-family: "Times New Roman", serif;">Relocated</span>的位置<span style="font-family: "Times New Roman", serif;">,</span>來做修正<span style="font-family: "Times New Roman", serif;">,</span>主要修正的方式為參考<span style="font-family: "Times New Roman", serif;">.rel.dyn Section</span>中的內容<span style="font-family: "Times New Roman", serif;">,</span>判斷其中<span style="font-family: "Times New Roman", serif;">Symbol</span>相依記憶體位置的屬性<span style="font-family: "Times New Roman", serif;">,</span>如果為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">a,fixrel: </span>就把最後<span style="font-family: "Times New Roman", serif;">Reolcated</span>的記憶體位址 跟 <span style="font-family: "Times New Roman", serif;">_TEXT_BASE</span>的<span style="font-family: "Times New Roman", serif;">Offset,</span>跟目前<span style="font-family: "Times New Roman", serif;">Symbol</span>的位址相加<span style="font-family: "Times New Roman", serif;">,</span>就可以修正<span style="font-family: "Times New Roman", serif;">Related</span>的位址對應<span style="font-family: "Times New Roman", serif;">.</span>最後修正 <span style="font-family: "Times New Roman", serif;">.rel.dyn Section</span>中<span style="font-family: "Times New Roman", serif;">Symbol</span>相依的位址<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">b,fixabs:</span>就把<span style="font-family: "Times New Roman", serif;">_dynsym_start_ofs</span>跟<span style="font-family: "Times New Roman", serif;">_TEXT_BASE</span>相加<span style="font-family: "Times New Roman", serif;">,</span>計算出該<span style="font-family: "Times New Roman", serif;">Symbol</span>的真實位址後<span style="font-family: "Times New Roman", serif;">,</span>再把最後<span style="font-family: "Times New Roman", serif;">Reolcated</span>的記憶體位址 跟 <span style="font-family: "Times New Roman", serif;">_TEXT_BASE</span>的<span style="font-family: "Times New Roman", serif;">Offset,</span>跟目前<span style="font-family: "Times New Roman", serif;">Symbol</span>的位址相加<span style="font-family: "Times New Roman", serif;">.</span>最後修正 <span style="font-family: "Times New Roman", serif;">.rel.dyn Section</span>中<span style="font-family: "Times New Roman", serif;">Symbol</span>相依的位址<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行完上述流程後<span style="font-family: "Times New Roman", serif;">,</span>就可以把 <span style="font-family: "Times New Roman", serif;">.rel.dyn Section</span>中<span style="font-family: "Times New Roman", serif;">Symbol</span>的參考<span style="font-family: "Times New Roman", serif;">,</span>都對應到最後<span style="font-family: "Times New Roman", serif;">Reolcated</span>的記憶體位址<span style="font-family: "Times New Roman", serif;">,</span>確保程式運作的正確性<span style="font-family: "Times New Roman", serif;">. </span>參考如下實作程式碼 <span style="font-family: "Times New Roman", serif;">(in arch/arm/cpu/armv7/start.S)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#ifndef CONFIG_PRELOADER</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/*</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">* fix .rel.dyn relocations</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">*/</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r0, _TEXT_BASE /* r0 <- Text base */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sub r9, r6, r0 /* r9 <- relocation offset */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r10, r10, r0 /* r10 <- sym table in FLASH */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r2, r2, r0 /* r2 <- rel dyn start in FLASH */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r3, r3, r0 /* r3 <- rel dyn end in FLASH */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">fixloop:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r0, r0, r9 /* r0 <- location to fix up in RAM */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r1, [r2, #4]</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">and r7, r1, #0xff</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">cmp r7, #23 /* relative fixup? */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">beq fixrel</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">cmp r7, #2 /* absolute fixup? */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">beq fixabs</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/* ignore unknown type of fixup */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">b fixnext</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">fixabs:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/* absolute fix: set location to (offset) symbol value */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r1, r10, r1 /* r1 <- address of symbol in table */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r1, [r1, #4] /* r1 <- symbol value */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r1, r1, r9 /* r1 <- relocated sym addr */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">b fixnext</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">fixrel:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/* relative fix: increase location by offset */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r1, [r0]</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r1, r1, r9</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">fixnext:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">str r1, [r0]</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r2, r2, #8 /* each rel.dyn entry is 8 bytes */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">cmp r2, r3</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">blo fixloop</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">clear_bss:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r0, _bss_start_ofs</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldr r1, _bss_end_ofs</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mov r4, r6 /* reloc addr */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r0, r0, r4</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r1, r1, r4</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mov r2, #0x00000000 /* clear</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">clbss_l:str r2, [r0] /* clear loop… */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">add r0, r0, #4</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">cmp r0, r1</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">bne clbss_l</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#endif /* #ifndef CONFIG_PRELOADER */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">5,</span>呼叫<span style="font-family: "Times New Roman", serif;">clear_bss,</span>並取 <span style="font-family: "Times New Roman", serif;">(_bss_start_ofs + Relocated</span>位址<span style="font-family: "Times New Roman", serif;">) </span>與 <span style="font-family: "Times New Roman", serif;">(_bss_end_ofs + Relocated</span>位址<span style="font-family: "Times New Roman", serif;">)</span>為區間<span style="font-family: "Times New Roman", serif;">,</span>把該區段記憶體設定為<span style="font-family: "Times New Roman", serif;">0.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">6,</span>進入函式 <span style="font-family: "Times New Roman", serif;">jump_2_ram,</span>在這會準備呼叫函式<span style="font-family: "Times New Roman", serif;">board_init_r</span>其中第一個參數為<span style="font-family: "Times New Roman", serif;">gd_t (Global Data Struct),</span>第二個參數為最後<span style="font-family: "Times New Roman", serif;">Relocated</span>的記憶體位址</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7,</span>進入函式<span style="font-family: "Times New Roman", serif;">board_init_r (</span>實作在<span style="font-family: "Times New Roman", serif;">arch/arm/lib/board.c</span>中<span style="font-family: "Times New Roman", serif;">),</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7.a,</span>首先會設定 <span style="font-family: "Times New Roman", serif;">gd->flags |= GD_FLG_RELOC,</span>表示<span style="font-family: "Times New Roman", serif;">Relocation </span>到外部記憶體的動作已經完成<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7.b,</span>呼叫函式<span style="font-family: "Times New Roman", serif;">board_init,</span>執行每個特定<span style="font-family: "Times New Roman", serif;">Board</span>所需的初始化流程<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7.c,</span>初始化<span style="font-family: "Times New Roman", serif;">UART Serial Port,Log Buffer,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7.d,</span>初始化在函式<span style="font-family: "Times New Roman", serif;">board_init_f</span>中預留在外部記憶體的<span style="font-family: "Times New Roman", serif;">Malloc</span>記憶體管理空間<span style="font-family: "Times New Roman", serif;">(</span>大小為<span style="font-family: "Times New Roman", serif;">TOTAL_MALLOC_LEN,</span>可以參考檔案<span style="font-family: "Times New Roman", serif;">include/common.h </span>與 <span style="font-family: "Times New Roman", serif;">include/configs/tegra2-common.h,</span>在<span style="font-family: "Times New Roman", serif;">tegra2</span>中該值為<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_MALLOC_LEN=(4 << 20) =4MB.).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7.e,</span>呼叫<span style="font-family: "Times New Roman", serif;">flash_init,</span>不過在筆者手中這版本<span style="font-family: "Times New Roman", serif;">,</span>會對記憶體定址的<span style="font-family: "Times New Roman", serif;">Flash</span>進行<span style="font-family: "Times New Roman", serif;">CRC32</span>的計算<span style="font-family: "Times New Roman", serif;">,</span>但並沒有比對<span style="font-family: "Times New Roman", serif;">CRC</span>值的正確性與否<span style="font-family: "Times New Roman", serif;">,…..so…</span>以開機效率而言<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_FLASH_CHECKSUM</span>選項<span style="font-family: "Times New Roman", serif;">,</span>應該可以不用打開<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7.f,</span>再來就會<span style="font-family: "Times New Roman", serif;">,</span>初始化<span style="font-family: "Times New Roman", serif;">NAND/One-Nand/MMC/ATMEL DataFlash </span>儲存媒體<span style="font-family: "Times New Roman", serif;">,</span>以<span style="font-family: "Times New Roman", serif;">NAND</span>為例<span style="font-family: "Times New Roman", serif;">,</span>會呼叫在檔案<span style="font-family: "Times New Roman", serif;">drivers/mtd/nand/nand.c</span>中的函式<span style="font-family: "Times New Roman", serif;">,nand_init</span>與<span style="font-family: "Times New Roman", serif;">nand_init_chip,</span>並呼叫到對應開發版根據自己硬體配置所實作的函式<span style="font-family: "Times New Roman", serif;">board_nand_init,</span>並把初始化完畢的<span style="font-family: "Times New Roman", serif;">NAND</span>周邊<span style="font-family: "Times New Roman", serif;">,</span>配置到<span style="font-family: "Times New Roman", serif;">MTD(Memory Technology Device)</span>的裝置中<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7.g,</span>執行<span style="font-family: "Times New Roman", serif;">env_relocate (initialize environment),drv_vfd_init ( must do this after the framebuffer is allocated ),</span>執行<span style="font-family: "Times New Roman", serif;">gd->bd->bi_ip_addr = getenv_IPaddr (“ipaddr”),</span>取得<span style="font-family: "Times New Roman", serif;">IP Address,stdio_init (“get the devices list going.”), jumptable_init,api_init (Initialize API),console_init_r (“fully init console as a device”), interrupt_init (“set up exceptions”), enable_interrupts(“enable exceptions”),</span>針對有支援的網卡進行初始化 <span style="font-family: "Times New Roman", serif;">(</span>像是網卡<span style="font-family: "Times New Roman", serif;">SMC91111 or LAN91C96),</span>取得相關環境變數 ”<span style="font-family: "Times New Roman", serif;">loadaddr” , “bootfile”,</span>與呼叫函式<span style="font-family: "Times New Roman", serif;">board_late_init,bb_miiphy_init,eth_initialize,reset_phy</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">8,</span>進入函式<span style="font-family: "Times New Roman", serif;">main_loop</span>中<span style="font-family: "Times New Roman", serif;">. (</span>在這支援互動的<span style="font-family: "Times New Roman", serif;">UBoot</span>命令<span style="font-family: "Times New Roman", serif;">.)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
多核心開機的流程與實現<span style="font-family: "Times New Roman", serif;">,</span>可以有多種不同的方式<span style="font-family: "Times New Roman", serif;">,</span>主要還是依據負責的<span style="font-family: "Times New Roman", serif;">Design Team</span>與做<span style="font-family: "Times New Roman", serif;">IC</span>架構夥伴的溝通與對於<span style="font-family: "Times New Roman", serif;">ARM</span>與<span style="font-family: "Times New Roman", serif;">SoC</span>平台的了解程度為主<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來<span style="font-family: "Times New Roman", serif;">,</span>我們參考<span style="font-family: "Times New Roman", serif;">Tegra2</span>的實作<span style="font-family: "Times New Roman", serif;">,</span>了解<span style="font-family: "Times New Roman", serif;">UBoot</span>在這方案上的多核心支援修改<span style="font-family: "Times New Roman", serif;">,</span>首先<span style="font-family: "Times New Roman", serif;">Tegra2 </span>包含了兩個<span style="font-family: "Times New Roman", serif;">Cortex A9 MPCore</span>處理器<span style="font-family: "Times New Roman", serif;">,</span>一個 <span style="font-family: "Times New Roman", serif;">AVP (Audio-Video Processor) ARM7TDMI </span>處理器<span style="font-family: "Times New Roman", serif;">,</span>與其他若干處理多媒體與<span style="font-family: "Times New Roman", serif;">Graphic</span>的處理器單元<span style="font-family: "Times New Roman", serif;">. </span>在開機流程中<span style="font-family: "Times New Roman", serif;">,</span>兩個<span style="font-family: "Times New Roman", serif;">Cortex A9 </span>與一個<span style="font-family: "Times New Roman", serif;">ARM7</span>處理器都會有對應的流程<span style="font-family: "Times New Roman", serif;">,</span>簡要描述如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>在函式 <span style="font-family: "Times New Roman", serif;">board_init_f (in arch/arm/lib/board.c) </span>中<span style="font-family: "Times New Roman", serif;">,</span>執行 <span style="font-family: "Times New Roman", serif;">init_sequence</span>中的函式<span style="font-family: "Times New Roman", serif;">board_early_init_f(in board/nvidia/common/board.c)</span>後<span style="font-family: "Times New Roman", serif;">,</span>會呼叫函式<span style="font-family: "Times New Roman", serif;">tegra2_start (in arch/arm/cpu/armv7/tegra2/ap20.c),</span>之後進入函式<span style="font-family: "Times New Roman", serif;">cpu_start,</span>由於是第一次啟動<span style="font-family: "Times New Roman", serif;">,</span>會先進入函式<span style="font-family: "Times New Roman", serif;">cold_boot (in arch/arm/cpu/armv7/tegra2/lowlevel_init.S).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,</span>如果判定自己是<span style="font-family: "Times New Roman", serif;">CPU (</span>在這就是<span style="font-family: "Times New Roman", serif;">Cortex A9)</span>的話<span style="font-family: "Times New Roman", serif;">,</span>就會跳到<span style="font-family: "Times New Roman", serif;">_armboot_start</span>執行 <span style="font-family: "Times New Roman", serif;">(</span>等於重新執行<span style="font-family: "Times New Roman", serif;">reset</span>的流程<span style="font-family: "Times New Roman", serif;">,</span>如果判定自己是<span style="font-family: "Times New Roman", serif;">AVP (</span>在這就是處理<span style="font-family: "Times New Roman", serif;">Audio/Video</span>的這顆<span style="font-family: "Times New Roman", serif;">ARM7),</span>就會繼續往後呼叫函式<span style="font-family: "Times New Roman", serif;">startup_cpu (in arch/arm/cpu/armv7/tegra2/lowlevel_init.S).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>會由<span style="font-family: "Times New Roman", serif;">ARM7</span>呼叫<span style="font-family: "Times New Roman", serif;">start_cpu (in arch/arm/cpu/armv7/tegra2/ap20.c),</span>用以設定<span style="font-family: "Times New Roman", serif;">TI PMU(Power Management Unit),</span>並把<span style="font-family: "Times New Roman", serif;">Cortex A9</span>設定為<span style="font-family: "Times New Roman", serif;">Reset,</span>與<span style="font-family: "Times New Roman", serif;">Disable Cortex A9 Clock,</span>並<span style="font-family: "Times New Roman", serif;">Enable CoreSight,</span>如果是在<span style="font-family: "Times New Roman", serif;">cold_boot (</span>也就是第一次啟動下<span style="font-family: "Times New Roman", serif;">),</span>就會設定<span style="font-family: "Times New Roman", serif;">Cortex A9 CPU</span>執行<span style="font-family: "Times New Roman", serif;">Reset Vector,</span>之後<span style="font-family: "Times New Roman", serif;">Enable Cortex A9 CPU#0</span>的<span style="font-family: "Times New Roman", serif;">Clock,</span>確認是否有透過<span style="font-family: "Times New Roman", serif;">PMU</span>供電<span style="font-family: "Times New Roman", serif;">,</span>並讓<span style="font-family: "Times New Roman", serif;">Cortex A9 CPU#0</span>離開<span style="font-family: "Times New Roman", serif;">Reset</span>狀態<span style="font-family: "Times New Roman", serif;">,</span>可以往後繼續執行<span style="font-family: "Times New Roman", serif;">. (</span>此時<span style="font-family: "Times New Roman", serif;">,Cortex A9 CPU#1</span>還是維持在 <span style="font-family: "Times New Roman", serif;">Disable Clock</span>與在<span style="font-family: "Times New Roman", serif;">Reset</span>的狀態<span style="font-family: "Times New Roman", serif;">),</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,</span>之後<span style="font-family: "Times New Roman", serif;">ARM7</span>會呼叫函式<span style="font-family: "Times New Roman", serif;">halt_avp (in arch/arm/cpu/armv7/tegra2/ap20.c),</span>讓自己進入<span style="font-family: "Times New Roman", serif;">Busy Loop(for(;;))</span>的暫停狀態中<span style="font-family: "Times New Roman", serif;">.(</span>設定<span style="font-family: "Times New Roman", serif;">FLOW_CTLR_HALT_COP_EVENTS)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">5,</span>此時<span style="font-family: "Times New Roman", serif;">,Cortex A9 CPU#0</span>就會重新從 <span style="font-family: "Times New Roman", serif;">start.S</span>中的<span style="font-family: "Times New Roman", serif;">reset</span>狀態往後執行<span style="font-family: "Times New Roman", serif;">,</span>在函式<span style="font-family: "Times New Roman", serif;">cpu_start</span>中<span style="font-family: "Times New Roman", serif;">,</span>由於是在<span style="font-family: "Times New Roman", serif;">ARM7</span>初始化後的執行<span style="font-family: "Times New Roman", serif;">,</span>此時<span style="font-family: "Times New Roman", serif;">s_first_boot</span>已經不為<span style="font-family: "Times New Roman", serif;">1,</span>所以不會呼叫到函式<span style="font-family: "Times New Roman", serif;">cold_boot,</span>在執行完<span style="font-family: "Times New Roman", serif;">cache_configure</span>後<span style="font-family: "Times New Roman", serif;">,</span>就會從函式<span style="font-family: "Times New Roman", serif;">tegra2_start</span>直接返回<span style="font-family: "Times New Roman", serif;">,</span>之後就會執行<span style="font-family: "Times New Roman", serif;">UBoot</span>後續的流程<span style="font-family: "Times New Roman", serif;">,</span>此時 <span style="font-family: "Times New Roman", serif;">ARM7 and Cortex A9#1 </span>都是在停止的狀態<span style="font-family: "Times New Roman", serif;">,</span>只有 <span style="font-family: "Times New Roman", serif;">Cortex A9#0</span>在執行 <span style="font-family: "Times New Roman", serif;">Uboot</span>的程式碼<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">6,</span>之後<span style="font-family: "Times New Roman", serif;">,</span>就根據是否有設定<span style="font-family: "Times New Roman", serif;">BOOTCOMMAND</span>與<span style="font-family: "Times New Roman", serif;">BOOT_DELAY,</span>來進行我們之前提過的<span style="font-family: "Times New Roman", serif;">UBoot</span>功能<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
運作的概念<span style="font-family: "Times New Roman", serif;">,</span>可以參考如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGnOK1oFu5d2g9eTGrhv_mMxbEJ2TXxyAeUQSoYYohak_SPieESETN2noQZjcjcbxu2plZABc_HG4nxH2jEJHsKpjw1IZ0EcQSyELhkBNU8jrOd-0SIjt1AuuyJp1ER6BkimDjFWy4tSg/s1600/LinuxKernelMultiProcessorBooting_html_5826fdd2%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="626" data-original-width="791" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGnOK1oFu5d2g9eTGrhv_mMxbEJ2TXxyAeUQSoYYohak_SPieESETN2noQZjcjcbxu2plZABc_HG4nxH2jEJHsKpjw1IZ0EcQSyELhkBNU8jrOd-0SIjt1AuuyJp1ER6BkimDjFWy4tSg/s1600/LinuxKernelMultiProcessorBooting_html_5826fdd2%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">而實作的機制除了上述</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">Tegra2</span><span style="font-size: 12.8px;">的例子外</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">,</span><span style="font-size: 12.8px;">參考</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">ARM</span><span style="font-size: 12.8px;">的文件</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">,</span><span style="font-size: 12.8px;">也可以讓除了主要初始化系統的處理器外</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">,</span><span style="font-size: 12.8px;">讓其它處理器透過</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">WFI Loop</span><span style="font-size: 12.8px;">的機制也同樣可以達到目的</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">.(</span><span style="font-size: 12.8px;">其實也相對比較單純一些</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">.). </span><span style="font-size: 12.8px;">整體運作的概念如下圖所示</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCv90E2EugWzNMCKXjfpXbqf46OEdZSWKtuhkaM7z6hVx64PFoI4saobt9kCNiMXMpuNWPBJdrfm51fAOYFNmcrCdCJCvt6IvxAnB8Q5-nh2vN3uM6BJt2lTE6P_10Fxee-uyVzXBJrOk/s1600/LinuxKernelMultiProcessorBooting_html_m4e511156%255B1%255D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="487" data-original-width="797" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCv90E2EugWzNMCKXjfpXbqf46OEdZSWKtuhkaM7z6hVx64PFoI4saobt9kCNiMXMpuNWPBJdrfm51fAOYFNmcrCdCJCvt6IvxAnB8Q5-nh2vN3uM6BJt2lTE6P_10Fxee-uyVzXBJrOk/s1600/LinuxKernelMultiProcessorBooting_html_m4e511156%255B1%255D.gif" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>透過 </strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>NAND</strong></span></span><span style="font-size: small;"><strong>載入 </strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Uboot </strong></span></span><span style="font-size: small;"><strong>的</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>NAND_SPL</strong></span></span><span style="font-size: small;"><strong>實作</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除了<span style="font-family: "Times New Roman", serif;">eMMC</span>外<span style="font-family: "Times New Roman", serif;">,NAND Flash</span>會是主打中低階產品時<span style="font-family: "Times New Roman", serif;">,</span>可以善加利用的儲存媒體<span style="font-family: "Times New Roman", serif;">,</span>而<span style="font-family: "Times New Roman", serif;">UBoot</span>也提供包括<span style="font-family: "Times New Roman", serif;">NAND</span>在內的前提<span style="font-family: "Times New Roman", serif;">Boot Loader,</span>主要目的是用以載入<span style="font-family: "Times New Roman", serif;">UBoot Image</span>要使用<span style="font-family: "Times New Roman", serif;">Uboot</span>的<span style="font-family: "Times New Roman", serif;">nand_spl</span>來載入<span style="font-family: "Times New Roman", serif;">UBoot,</span>我們可以在下載 <span style="font-family: "Times New Roman", serif;">u-boot-2011.06-rc3</span>版本後<span style="font-family: "Times New Roman", serif;">,</span>選擇目前有這樣子實作的<span style="font-family: "Times New Roman", serif;">Samsung SMDK6400</span>環境<span style="font-family: "Times New Roman", serif;">,</span>執行如下指令<span style="font-family: "Times New Roman", serif;">,</span>就可以開始編譯流程</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">make smdk6400_config</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">make</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就會在<span style="font-family: "Times New Roman", serif;">nand_spl</span>目錄下產生<span style="font-family: "Times New Roman", serif;">u-boot-spl.bin</span>與<span style="font-family: "Times New Roman", serif;">u-boot-spl-16k.bin,</span>兩者差異在於後者透過<span style="font-family: "Times New Roman", serif;">arm-eabi-objcopy</span>時<span style="font-family: "Times New Roman", serif;">,</span>會加上 <span style="font-family: "Times New Roman", serif;">– -pad-to </span>選項<span style="font-family: "Times New Roman", serif;">,</span>讓工具產生的<span style="font-family: "Times New Roman", serif;">Image</span>可以對齊<span style="font-family: "Times New Roman", serif;">4096 bytes</span>的大小<span style="font-family: "Times New Roman", serif;">,</span>由於筆者所產生的<span style="font-family: "Times New Roman", serif;">Image</span>大小為<span style="font-family: "Times New Roman", serif;">3028bytes,</span>所以<span style="font-family: "Times New Roman", serif;">u-boot-spl.bin</span>大小為<span style="font-family: "Times New Roman", serif;">3028bytes,</span>而<span style="font-family: "Times New Roman", serif;">u-boot-spl-16k.bin</span>大小為<span style="font-family: "Times New Roman", serif;">4096bytes.</span>產生的指令如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">arm-eabi-objcopy –gap-fill=0xff -O binary /home/loda/u-boot-2011.06-rc3/nand_spl/u-boot-spl /home/loda/u-boot-2011.06-rc3/nand_spl/u-boot-spl.bin</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">arm-eabi-objcopy –gap-fill=0xff –pad-to=4096 -O binary /home/loda/u-boot-2011.06-rc3/nand_spl/u-boot-spl /home/loda/u-boot-2011.06-rc3/nand_spl/u-boot-spl-16k.bin</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過 <span style="font-family: "Times New Roman", serif;">Uboot nand_spl</span>實現<span style="font-family: "Times New Roman", serif;">UBoot NAND Flash</span>載入機制的運作流程為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,CPU</span>啟動後<span style="font-family: "Times New Roman", serif;">,</span>由<span style="font-family: "Times New Roman", serif;">Boot Rom</span>把<span style="font-family: "Times New Roman", serif;">NAND Flash</span>第一個<span style="font-family: "Times New Roman", serif;">Block</span>中的<span style="font-family: "Times New Roman", serif;">nand_spl</span>的程式碼載入記憶體<span style="font-family: "Times New Roman", serif;">(</span>第一個<span style="font-family: "Times New Roman", serif;">Block</span>會保證在一定寫入次數內<span style="font-family: "Times New Roman", serif;">,</span>都可以正確的讀出<span style="font-family: "Times New Roman", serif;">.).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,</span>如果<span style="font-family: "Times New Roman", serif;">BootRom</span>有初始化外部記憶體<span style="font-family: "Times New Roman", serif;">,</span>就可以直接載入到外部記憶體中執行<span style="font-family: "Times New Roman", serif;">,</span>或是載入到<span style="font-family: "Times New Roman", serif;">OnChip RAM,</span>由<span style="font-family: "Times New Roman", serif;">nand_spl</span>進行外部記憶體的初始化<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>跳到<span style="font-family: "Times New Roman", serif;">nand_spl</span>中執行<span style="font-family: "Times New Roman", serif;">. </span>並由<span style="font-family: "Times New Roman", serif;">nand_spl</span>初始化 處理器<span style="font-family: "Times New Roman", serif;">,</span>外部記憶體<span style="font-family: "Times New Roman", serif;">,</span>並會透過函式<span style="font-family: "Times New Roman", serif;">board_init_f (</span>實作在 <span style="font-family: "Times New Roman", serif;">nand_spl/board/samsung/smdk6400/smdk6400_nand_spl.c</span>中<span style="font-family: "Times New Roman", serif;">)</span>把<span style="font-family: "Times New Roman", serif;">nand_spl</span>本身拷貝到指定的外部記憶體中<span style="font-family: "Times New Roman", serif;">. (mmmmm,</span>也就是說 <span style="font-family: "Times New Roman", serif;">Samsung smdk6400</span>的實作本身<span style="font-family: "Times New Roman", serif;">,</span>就假設在這<span style="font-family: "Times New Roman", serif;">ARM1176</span>的平台上會有至少大約<span style="font-family: "Times New Roman", serif;">4kbytes</span>的<span style="font-family: "Times New Roman", serif;">OnChip RAM).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考如下程式碼 <span style="font-family: "Times New Roman", serif;">( relocate_code</span>第一個參數為<span style="font-family: "Times New Roman", serif;">addr_sp,</span>第二個參數為<span style="font-family: "Times New Roman", serif;">addr_gd,</span>地三個參數為 <span style="font-family: "Times New Roman", serif;">addr_destination)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">void board_init_f(unsigned long bootflag)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">relocate_code(CONFIG_SYS_TEXT_BASE – TOTAL_MALLOC_LEN, NULL,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_TEXT_BASE);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在檔案<span style="font-family: "Times New Roman", serif;">nand_spl/board/samsung/smdk6400/start.S </span>中<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">…</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.globl relocate_code</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">relocate_code:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mov r4, r0 /* save addr_sp */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mov r5, r1 /* save addr of gd */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mov r6, r2 /* save addr of destination */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">…….</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">copy_loop:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ldmia r0!, {r9-r10} /* copy from source address [r0] */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">stmia r1!, {r9-r10} /* copy to target address [r1] */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">cmp r0, r2 /* until source end address [r2] */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">blo copy_loop</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">..</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,</span>接下來由<span style="font-family: "Times New Roman", serif;">nand_spl</span>把<span style="font-family: "Times New Roman", serif;">UBoot</span>本身從<span style="font-family: "Times New Roman", serif;">NAND Flash</span>中複製到外部記憶體的記憶體位址<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_NAND_U_BOOT_DST</span>中<span style="font-family: "Times New Roman", serif;">,</span>並且到記憶體位址<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_NAND_U_BOOT_START</span>執行<span style="font-family: "Times New Roman", serif;">UBoot Image.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">5,</span>同樣的<span style="font-family: "Times New Roman", serif;">UBoot Image</span>也會有自己的函式<span style="font-family: "Times New Roman", serif;">board_init_f</span>執行<span style="font-family: "Times New Roman", serif;">,</span>並透過 <span style="font-family: "Times New Roman", serif;">relocate_code</span>函式<span style="font-family: "Times New Roman", serif;">,</span>可以把自己重定位到編譯<span style="font-family: "Times New Roman", serif;">UBoot</span>時<span style="font-family: "Times New Roman", serif;">,</span>指定的<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_TEXT_BASE </span>記憶體位址中<span style="font-family: "Times New Roman", serif;">.</span>同樣的<span style="font-family: "Times New Roman", serif;">,</span>如果<span style="font-family: "Times New Roman", serif;">CONFIG_SYS_TEXT_BASE </span>等於要重定位過去的記憶體位置<span style="font-family: "Times New Roman", serif;">,</span>重定位的動作就會省略<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下程式碼所示 <span style="font-family: "Times New Roman", serif;">(</span>在檔案<span style="font-family: "Times New Roman", serif;">nand_spl/board/samsung/smdk6400/start.S</span>中<span style="font-family: "Times New Roman", serif;">)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">cmp r0, r6 // r0 = _start , r6=CONFIG_SYS_TEXT_BASE</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">beq clear_bss /* skip relocation */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此外<span style="font-family: "Times New Roman", serif;">,</span>如果在<span style="font-family: "Times New Roman", serif;">nand_spl</span>中已經對<span style="font-family: "Times New Roman", serif;">CPU</span>與<span style="font-family: "Times New Roman", serif;">RAM</span>初始化<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">UBoot</span>中就不需要重新初始化<span style="font-family: "Times New Roman", serif;">,</span>可直接進行 <span style="font-family: "Times New Roman", serif;">bss clear </span>並執行函式 <span style="font-family: "Times New Roman", serif;">board_init_r</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>結語</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文主要著眼於根據<span style="font-family: "Times New Roman", serif;">ARM MPCore</span>下<span style="font-family: "Times New Roman", serif;">,Boot Rom</span>與 <span style="font-family: "Times New Roman", serif;">UBoot</span>的流程與行為介紹<span style="font-family: "Times New Roman", serif;">,</span>下一篇文章將會針對<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>在<span style="font-family: "Times New Roman", serif;">ARM MPCore</span>上<span style="font-family: "Times New Roman", serif;">SMP</span>啟動流程加以說明<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以目前<span style="font-family: "Times New Roman", serif;">Android</span>產品來說<span style="font-family: "Times New Roman", serif;">,ARM MPCore</span>架構幾乎會是未來的主流<span style="font-family: "Times New Roman", serif;">,</span>除了可以在達到同樣效能的目標下<span style="font-family: "Times New Roman", serif;">,</span>減少功耗的消耗外<span style="font-family: "Times New Roman", serif;">,</span>對於多工<span style="font-family: "Times New Roman", serif;">(Multi-Task)</span>作業系統的效能上<span style="font-family: "Times New Roman", serif;">,</span>也有很顯著的加分<span style="font-family: "Times New Roman", serif;">. </span>對於參與<span style="font-family: "Times New Roman", serif;">Andriod</span>平台維護的開發者<span style="font-family: "Times New Roman", serif;">,</span>在這部份系統能力的建立<span style="font-family: "Times New Roman", serif;">,</span>會是非常重要的一環<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有任何關於技術的討論<span style="font-family: "Times New Roman", serif;">,</span>都歡迎與我聯繫<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-71584776078067733932017-06-01T10:03:00.002-07:002017-06-03T08:31:15.132-07:00ARM與Cortex筆記-ARM MPCore (Multi-Processor Core) 多核心架構解析.<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
ARM與Cortex筆記-ARM MPCore (Multi-Processor Core) 多核心架構解析.</h1>
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">ARM</span>與<span style="font-family: "times new roman" , serif;">Cortex</span>筆記<span style="font-family: "times new roman" , serif;">–</span><span style="font-family: "times new roman" , serif;">ARM MPCore (Multi-Processor Core) 多核心</span>架構解析<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "times new roman" , serif;">hlchou@mail2000.com.tw</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "times new roman" , serif;">by loda</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>隨著目前<span style="font-family: "times new roman" , serif;">Smart Phone</span>的應用與複雜度增加<span style="font-family: "times new roman" , serif;">,</span>這類消費性電子產品<span style="font-family: "times new roman" , serif;">,</span>必須要能在考量功耗與持久性的前提下<span style="font-family: "times new roman" , serif;">,</span>達成使用者可接受的高效能<span style="font-family: "times new roman" , serif;">,</span>並且還要有足夠的使用與待機時間<span style="font-family: "times new roman" , serif;">,</span>基於如此<span style="font-family: "times new roman" , serif;">,ARM MPCore</span>多核心架構<span style="font-family: "times new roman" , serif;">,</span>就是一個在消費性電子產品上可以考慮的處理器架構選擇<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>參考<span style="font-family: "times new roman" , serif;">ARM</span>網站有關<span style="font-family: "times new roman" , serif;">Cortex A9 Performance</span>的介紹<span style="font-family: "times new roman" , serif;">(<span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://www.arm.com/products/processors/cortex-a/cortex-a9.php" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.arm.com/products/processors/cortex-a/cortex-a9.php</a></span></span> ),</span>以雙核心架構在<span style="font-family: "times new roman" , serif;">TSMC 40G</span>性能優化的版本中<span style="font-family: "times new roman" , serif;">,</span>效能與功耗比為<span style="font-family: "times new roman" , serif;">5.26 (DMIPS/mW),</span>而<span style="font-family: "times new roman" , serif;">Cortex A9</span>單一核心的<span style="font-family: "times new roman" , serif;">Dhrystone </span>性能比為<span style="font-family: "times new roman" , serif;">2.50 DMIPS/MHz,</span>也就是說<span style="font-family: "times new roman" , serif;">,</span>如果希望要達到<span style="font-family: "times new roman" , serif;">10000DMIPS,</span>以單核心而言就需要達到<span style="font-family: "times new roman" , serif;">2GHz</span>的時脈<span style="font-family: "times new roman" , serif;">,</span>此時的總功耗約為<span style="font-family: "times new roman" , serif;">1.9W (= 10000/5.26),</span>但如果是以多核心的架構<span style="font-family: "times new roman" , serif;">,</span>就可以在時脈不需要大幅拉到<span style="font-family: "times new roman" , serif;">2GHz</span>的情況下<span style="font-family: "times new roman" , serif;">,</span>透過增加處理器數量<span style="font-family: "times new roman" , serif;">,</span>來達到所期待的運算<span style="font-family: "times new roman" , serif;">DMIPS</span>總數<span style="font-family: "times new roman" , serif;">,</span>而且系統功耗增加幅度也低<span style="font-family: "times new roman" , serif;">(</span>當然晶片的面積會增加<span style="font-family: "times new roman" , serif;">),</span>可以參考這份<span style="font-family: "times new roman" , serif;">ARM</span>的投影片<span style="font-family: "times new roman" , serif;">“Parallel Computing in your Pocket” (</span>參考網址<span style="font-family: "times new roman" , serif;">:http://www.iet-cambridge.org.uk/arc/seminar07/slides/JohnGoodacre.pdf),</span>可以看到單核心要達到三核心的效能時<span style="font-family: "times new roman" , serif;">,</span>透過拉高時脈達到一樣的效能時<span style="font-family: "times new roman" , serif;">,</span>核心的總功耗會是採用三核心方案的三倍以上<span style="font-family: "times new roman" , serif;">,</span>也就是說<span style="font-family: "times new roman" , serif;">,</span>如果作業系統上有適度的<span style="font-family: "times new roman" , serif;">Muti-Task</span>多工<span style="font-family: "times new roman" , serif;">,</span>用多核心去滿足總體效能的期待<span style="font-family: "times new roman" , serif;">,</span>會比單核心的架構<span style="font-family: "times new roman" , serif;">,</span>更符合省電的功耗效益<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>在多核心的架構下<span style="font-family: "times new roman" , serif;">,</span>還需要去檢視作業系統的排程機制<span style="font-family: "times new roman" , serif;">,</span>若<span style="font-family: "times new roman" , serif;">OS Scheduling Tick</span>是透過<span style="font-family: "times new roman" , serif;">Interrupt Distributor</span>發給每個處理器<span style="font-family: "times new roman" , serif;">,</span>則每個處理器都會透過執行排程的程式碼<span style="font-family: "times new roman" , serif;">,</span>選擇需要執行的<span style="font-family: "times new roman" , serif;">Task,</span>進行<span style="font-family: "times new roman" , serif;">Task Context-Switch</span>的流程<span style="font-family: "times new roman" , serif;">,</span>這樣的想法對於讓系統<span style="font-family: "times new roman" , serif;">Best-Effort</span>運作是比較合理的<span style="font-family: "times new roman" , serif;">,</span>但對於消費性產品而言<span style="font-family: "times new roman" , serif;">,</span>若可以讓系統盡可能省電<span style="font-family: "times new roman" , serif;">,</span>而又只會減損些微的效能<span style="font-family: "times new roman" , serif;">,</span>反而是種加分<span style="font-family: "times new roman" , serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也因此<span style="font-family: "times new roman" , serif;">,</span>除了要確保每個處理器可以透過<span style="font-family: "times new roman" , serif;">WFI</span>進入省電狀態外<span style="font-family: "times new roman" , serif;">,</span>若是把<span style="font-family: "times new roman" , serif;">OS Scheduling Tick</span>固定發給<span style="font-family: "times new roman" , serif;">Primary Processor,</span>其它目前沒有<span style="font-family: "times new roman" , serif;">Task</span>執行的處理器<span style="font-family: "times new roman" , serif;">,</span>就進入<span style="font-family: "times new roman" , serif;">WFI</span>的狀態<span style="font-family: "times new roman" , serif;">,</span>由該<span style="font-family: "times new roman" , serif;">Primary Processor</span>進行排程與工作分配<span style="font-family: "times new roman" , serif;">,non-Primary Processor</span>接收到來自<span style="font-family: "times new roman" , serif;">Primary Processor</span>的<span style="font-family: "times new roman" , serif;">IPI</span>中斷後<span style="font-family: "times new roman" , serif;">,</span>就會被喚醒<span style="font-family: "times new roman" , serif;">,</span>進行對應的<span style="font-family: "times new roman" , serif;">Task Context-Switch</span>動作<span style="font-family: "times new roman" , serif;">,</span>如果系統是處於不忙碌的狀態下<span style="font-family: "times new roman" , serif;">,</span>就會有機會讓<span style="font-family: "times new roman" , serif;">non-Primary Processor</span>的處理器<span style="font-family: "times new roman" , serif;">,</span>有機會維持比較長時間的<span style="font-family: "times new roman" , serif;">StandBy</span>休眠的狀態<span style="font-family: "times new roman" , serif;">,MPCore</span>的消費性產品<span style="font-family: "times new roman" , serif;">,</span>可以維持比較長時間的運作<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>本文主要以<span style="font-family: "times new roman" , serif;">ARMv7 </span>與<span style="font-family: "times new roman" , serif;">CortexA9</span>為主要討論的範圍<span style="font-family: "times new roman" , serif;">(</span>可供參考的文件例如<span style="font-family: "times new roman" , serif;">:ARMv7-AR Architecture Reference Manual),</span>所討論的內容<span style="font-family: "times new roman" , serif;">,</span>主要以筆者認為值得深入討論的項目<span style="font-family: "times new roman" , serif;">,</span>並不一定符合每個人對於<span style="font-family: "times new roman" , serif;">ARM MPCore</span>所需的範圍<span style="font-family: "times new roman" , serif;">,</span>最後<span style="font-family: "times new roman" , serif;">,</span>本文雖盡可能提供正確的資訊<span style="font-family: "times new roman" , serif;">,</span>若有不盡完善之處<span style="font-family: "times new roman" , serif;">,</span>請以<span style="font-family: "times new roman" , serif;">ARM</span>的文件為依歸<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>多核心架構的概念</strong></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>多核心的架構下<span style="font-family: "times new roman" , serif;">,</span>開機時<span style="font-family: "times new roman" , serif;">,</span>只會有一個處理器在運作稱為<span style="font-family: "times new roman" , serif;">Primary Processor(</span>或導引處理器<span style="font-family: "times new roman" , serif;">BSP “bootstrap processor “),</span>其它處理器則稱為 <span style="font-family: "times new roman" , serif;">non-Primary Processor(</span>或應用處理器<span style="font-family: "times new roman" , serif;">AP “Application processor”),</span>在系統初始化與關機過程中<span style="font-family: "times new roman" , serif;">,</span>都是由<span style="font-family: "times new roman" , serif;">Primary Processor</span>來負責<span style="font-family: "times new roman" , serif;">,</span>主要執行如下流程</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">1,Invalidate Data Cache</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">2,Invalidate SCU(Snoop Control Unit) duplicate tags for all processors</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">3,Invalidate L2 Cache</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">4,Enable SCU</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">5,Enable Data Cache</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">6. Enable L2 Cache</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">7. Set SMP mode with ACTLR.SMP.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>等到作業系統初始一個段落後<span style="font-family: "times new roman" , serif;">,</span>才會去啟動其它的<span style="font-family: "times new roman" , serif;">non-Primary Processor,</span>並由這些處理器執行如下流程</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">1. Invalidate Data Cache</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">2. Enable Data Cache</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">3. Set SMP with ACTLR.SMP.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>整個系統的排程機制就會根據這些啟動的<span style="font-family: "times new roman" , serif;">Processor</span>來分派工作<span style="font-family: "times new roman" , serif;">,</span>如果有用不到的處理器資源<span style="font-family: "times new roman" , serif;">,</span>也可以透過<span style="font-family: "times new roman" , serif;">WFI(Wait For Interrupr)</span>讓處理器處於省電的模式<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>基於多處理器的架構<span style="font-family: "times new roman" , serif;">,</span>處理器也會提供硬體層級支援記憶體同步的指令<span style="font-family: "times new roman" , serif;">,</span>例如<span style="font-family: "times new roman" , serif;">:LDREX, STREX, SWP</span>與 <span style="font-family: "times new roman" , serif;">SWPB,</span>避免當有一個以上的處理器對同一個記憶體內容存取時<span style="font-family: "times new roman" , serif;">,</span>當該內容在處理器<span style="font-family: "times new roman" , serif;">A</span>中有做變動<span style="font-family: "times new roman" , serif;">,</span>以致使該內容在處理器<span style="font-family: "times new roman" , serif;">B</span>中失效時<span style="font-family: "times new roman" , serif;">,</span>可以透過這類指令確保處理器<span style="font-family: "times new roman" , serif;">B</span>可以同步到最新的內容<span style="font-family: "times new roman" , serif;">,</span>維持整個系統運作的正確性<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>而在作業系統中<span style="font-family: "times new roman" , serif;">SpinLock</span>的機制<span style="font-family: "times new roman" , serif;">,</span>也會透過<span style="font-family: "times new roman" , serif;">LDREX/STREX</span>來進行<span style="font-family: "times new roman" , serif;">,</span>確保當作業系統進行<span style="font-family: "times new roman" , serif;">SpinLock</span>動作時<span style="font-family: "times new roman" , serif;">,</span>可以得到硬體層級的記憶體同步確保<span style="font-family: "times new roman" , serif;">,</span>避免<span style="font-family: "times new roman" , serif;">SpinLock</span>在多核心架構下的運作失誤<span style="font-family: "times new roman" , serif;">. (</span>透過軟體<span style="font-family: "times new roman" , serif;">,</span>要做到比硬體支援更有效率的自旋鎖是相對困難<span style="font-family: "times new roman" , serif;">),</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>參考<span style="font-family: "times new roman" , serif;">Linux Kernel</span>在<span style="font-family: "times new roman" , serif;">ARM</span>平台上的<span style="font-family: "times new roman" , serif;">SpinLock</span>實作<span style="font-family: "times new roman" , serif;">(</span>檔案位置<span style="font-family: "times new roman" , serif;">arch/arm/include/asm/spinlock.h),</span>如下所示</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">static inline void __raw_spin_lock(raw_spinlock_t *lock)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">unsigned long tmp;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">__asm__ __volatile__(</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">“1: <span style="color: red;"><strong>ldrex</strong></span> %0, [%1]\n”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">” teq %0, #0\n”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">#ifdef CONFIG_CPU_32v6K</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">” wfene\n”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">#endif</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">” <span style="color: red;"><strong>strexeq</strong></span> %0, %2, [%1]\n”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">” teqeq %0, #0\n”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">” bne 1b”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">: “=&r” (tmp)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">: “r” (&lock->lock), “r” (1)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">: “cc”);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">smp_mb();</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">static inline int __raw_spin_trylock(raw_spinlock_t *lock)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">unsigned long tmp;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">__asm__ __volatile__(</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">” <span style="color: red;"><strong>ldrex</strong></span> %0, [%1]\n”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">” teq %0, #0\n”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">” <span style="color: red;"><strong>strexeq</strong></span> %0, %2, [%1]”</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">: “=&r” (tmp)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">: “r” (&lock->lock), “r” (1)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">: “cc”);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">if (tmp == 0) {</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">smp_mb();</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">return 1;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">} else {</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">return 0;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>此外<span style="font-family: "times new roman" , serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">1, </span>處理器之間可透過<span style="font-family: "times new roman" , serif;">IPI(Inter-Processor Interrupt)</span>彼此溝通<span style="font-family: "times new roman" , serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">2,</span>處理器之間是合作關係<span style="font-family: "times new roman" , serif;">,</span>彼此沒有從屬的關係<span style="font-family: "times new roman" , serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">3,</span>所有的處理器都看到同樣的記憶體空間<span style="font-family: "times new roman" , serif;">,</span>彼此所定址的實體記憶體空間也是一樣<span style="font-family: "times new roman" , serif;">,</span>在同樣的記憶體位置上都是存取同樣的記憶體內容<span style="font-family: "times new roman" , serif;">.</span>並且<span style="font-family: "times new roman" , serif;">,</span>共同基於同一個作業系統程式碼<span style="font-family: "times new roman" , serif;">,</span>來對所有的處理器進行<span style="font-family: "times new roman" , serif;">Task</span>的排程工作<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">4,</span>每個處理器都是以<span style="font-family: "times new roman" , serif;">Task</span>為單位去進行多工<span style="font-family: "times new roman" , serif;">,</span>但進入到<span style="font-family: "times new roman" , serif;">Kernel Mode (Ring0 or Supervisor Mode)</span>時<span style="font-family: "times new roman" , serif;">,</span>所看到的記憶體內容是同一塊被保護的區間<span style="font-family: "times new roman" , serif;">,</span>但是切到<span style="font-family: "times new roman" , serif;">User Mode (Ring 3 or User Mode)</span>時<span style="font-family: "times new roman" , serif;">,</span>就是根據<span style="font-family: "times new roman" , serif;">MMU</span>看到各自的記憶體區塊<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">5,</span>所有的處理器都共享同樣的<span style="font-family: "times new roman" , serif;">I/O</span>周邊與中斷控制器<span style="font-family: "times new roman" , serif;">,</span>每個處理器都可以收到來自任何周邊的中斷觸發<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>檢視</strong></span><span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>ARM MPCore</strong></span></span><span style="font-size: small;"><strong>架構</strong></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">ARM</span>系列在<span style="font-family: "times new roman" , serif;">ARM11(</span>例如<span style="font-family: "times new roman" , serif;">:ARM1176)</span>時<span style="font-family: "times new roman" , serif;">,</span>就已經導入<span style="font-family: "times new roman" , serif;">Multi-Processor Core</span>的架構<span style="font-family: "times new roman" , serif;">,Cortex</span>系列<span style="font-family: "times new roman" , serif;">,</span>包括<span style="font-family: "times new roman" , serif;">A5,A9</span>跟<span style="font-family: "times new roman" , serif;">A15</span>都支援<span style="font-family: "times new roman" , serif;">MPCore</span>的架構<span style="font-family: "times new roman" , serif;">,</span>目前可以支援<span style="font-family: "times new roman" , serif;">4</span>個核心架構<span style="font-family: "times new roman" , serif;">(</span>可以參考文件<span style="font-family: "times new roman" , serif;">: ARM11 MPCore Processor Technical Reference Manual in <span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/topic/com.arm.doc.ddi0360f/DDI0360F_arm11_mpcore_r2p0_trm.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/topic/com.arm.doc.ddi0360f/DDI0360F_arm11_mpcore_r2p0_trm.pdf </a></span></span></span>或 <span style="font-family: "times new roman" , serif;">Cortex-A9 MPCore Technical Reference Manual in <span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/topic/com.arm.doc.ddi0407e/DDI0407E_cortex_a9_mpcore_r2p0_trm.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/topic/com.arm.doc.ddi0407e/DDI0407E_cortex_a9_mpcore_r2p0_trm.pdf</a></span></span> ), </span>多核心的架構會透過<span style="font-family: "times new roman" , serif;">Snoop Control Unit</span>介面同步每個處理器各自的<span style="font-family: "times new roman" , serif;">L1 Data Cache</span>內容<span style="font-family: "times new roman" , serif;">,</span>並以<span style="font-family: "times new roman" , serif;">Distributed Interrupt Controller</span>支援既有的<span style="font-family: "times new roman" , serif;">ARM Interrupts,</span>每個處理器都有一個專屬的<span style="font-family: "times new roman" , serif;">Timer</span>與<span style="font-family: "times new roman" , serif;">WatchDog,</span>支援<span style="font-family: "times new roman" , serif;">Level 2 AMBA(AXI high-speed Advanced Microprocessor Bus Architecture)</span>介面<span style="font-family: "times new roman" , serif;">,</span>每個處理器都有一個<span style="font-family: "times new roman" , serif;">Integral EmbeddedICE-RT Logic</span>用以提供<span style="font-family: "times new roman" , serif;">JTAG</span>除錯介面<span style="font-family: "times new roman" , serif;">,</span>與各自的<span style="font-family: "times new roman" , serif;">Pipeline,Branch Prediction with Return Stack,</span>與<span style="font-family: "times new roman" , serif;">CoProcessors 14 and 15,</span>每個處理器都有自己的<span style="font-family: "times new roman" , serif;">MMU (Instruction and Data Memory Management Units),</span>主要的差異在於處理器對分頁的處理不是直接跟單核心架構一樣去操作<span style="font-family: "times new roman" , serif;">TLB,</span>而是每個處理器都維護自己的<span style="font-family: "times new roman" , serif;">Micro TLB,</span>並透過共用的<span style="font-family: "times new roman" , serif;">Main TLB</span>同步<span style="font-family: "times new roman" , serif;">,</span>每個處理器都有<span style="font-family: "times new roman" , serif;">L1 Instruction/Data Cache,</span>每個處理器都具備對外的<span style="font-family: "times new roman" , serif;">32-bit Instruction Interface</span>與<span style="font-family: "times new roman" , serif;">64-bit Data Cache,</span>每個處理器都支援硬體的<span style="font-family: "times new roman" , serif;">Data Cache Coherence,</span>每個處理器都可提供<span style="font-family: "times new roman" , serif;">Vector Floating-Point (VFP) Coprocessor </span>支援</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">ARM MPCore</span>架構與周邊運作示意圖</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3MLmJLpP7pSnfyhbEdUNe-cJAe2BHPvLISfO3DLs2hnut8Oem7a8U3qqgtFqnqpdV2y0z4RAbyVrYP08DAripNurliN3w2llCP24kuRmftGpVAh8Dw8idgDiTpMraMIll2xRJjYzdUGI/s1600/image002%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="598" data-original-width="801" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3MLmJLpP7pSnfyhbEdUNe-cJAe2BHPvLISfO3DLs2hnut8Oem7a8U3qqgtFqnqpdV2y0z4RAbyVrYP08DAripNurliN3w2llCP24kuRmftGpVAh8Dw8idgDiTpMraMIll2xRJjYzdUGI/s1600/image002%255B1%255D.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>Interrupt Distributor</strong></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MPCore </span>的架構下會透過 <span style="font-family: "times new roman" , serif;">Interrupt Distributor </span>統一管理<span style="font-family: "times new roman" , serif;">MPCore</span>上所有處理器的中斷來源<span style="font-family: "times new roman" , serif;">,</span>並且依據中斷優先級分派中斷給個別的處理器<span style="font-family: "times new roman" , serif;">.</span>每個中斷來源<span style="font-family: "times new roman" , serif;">,</span>都可以設定優先級<span style="font-family: "times new roman" , serif;">,</span>以及當該中斷發生時<span style="font-family: "times new roman" , serif;">,</span>哪些處理器要收到該中斷要求<span style="font-family: "times new roman" , serif;">.</span>在硬體支援上<span style="font-family: "times new roman" , serif;">,</span>會確保一個發送給多處理器的中斷<span style="font-family: "times new roman" , serif;">,</span>一次只有一個處理器在處理<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>以<span style="font-family: "times new roman" , serif;">Cortex A9</span>為例<span style="font-family: "times new roman" , serif;">,Interrupr Distributor</span>支援<span style="font-family: "times new roman" , serif;">224</span>個中斷來源<span style="font-family: "times new roman" , serif;">,</span>每個中斷源都有唯一的<span style="font-family: "times new roman" , serif;">ID</span>識別<span style="font-family: "times new roman" , serif;">(ID0-ID223),</span>有關中斷來源分類如下所示</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="196"></col><col width="586"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="196"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
來源</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="586"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="196"><span style="font-family: "times new roman" , serif;">Software Generated Interrupts (SGI)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="586">可用於<span style="font-family: "times new roman" , serif;">Inter-Processor Interrupts (IPI).</span>每個<span style="font-family: "times new roman" , serif;">MPCore</span>中的處理器都會有<span style="font-family: "times new roman" , serif;">Private Interrupt </span>範圍從<span style="font-family: "times new roman" , serif;">ID0</span>到<span style="font-family: "times new roman" , serif;">ID15,</span>並且只能由軟體觸發中斷<span style="font-family: "times new roman" , serif;">. </span>中斷的優先級<span style="font-family: "times new roman" , serif;">,</span>會由每個接收中斷的處理器自行設定決定<span style="font-family: "times new roman" , serif;">,</span>發出中斷的處理器無法決定接收端的優先級<span style="font-family: "times new roman" , serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="196"><span style="font-family: "times new roman" , serif;">Global timer (PPI(0))</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="586">透過<span style="font-family: "times new roman" , serif;">Interrupt Distributor </span>使用中斷<span style="font-family: "times new roman" , serif;">ID27</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="196"><span style="font-family: "times new roman" , serif;">A legacy nFIQ pin (PPI(1))</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="586">如果選擇<span style="font-family: "times new roman" , serif;">Legacy FIQ mode,</span>就會跳過<span style="font-family: "times new roman" , serif;">Interrupt Distributor</span>直接把中斷發給每個<span style="font-family: "times new roman" , serif;">MPCore</span>處理器<span style="font-family: "times new roman" , serif;">.</span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
反之<span style="font-family: "times new roman" , serif;">,</span>就會藉由<span style="font-family: "times new roman" , serif;">Distributed Interrupt Controller</span>把<span style="font-family: "times new roman" , serif;">FIQ</span>以中斷<span style="font-family: "times new roman" , serif;">ID28</span>發給<span style="font-family: "times new roman" , serif;">MPCore</span>的處理器<span style="font-family: "times new roman" , serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="196"><span style="font-family: "times new roman" , serif;">Private timer, PPI(2)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="586">每個<span style="font-family: "times new roman" , serif;">MPCore</span>中的處理器會以中斷 <span style="font-family: "times new roman" , serif;">ID29</span>作為<span style="font-family: "times new roman" , serif;">Private Timer</span>中斷源<span style="font-family: "times new roman" , serif;">.</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="196"><span style="font-family: "times new roman" , serif;">Watchdog timers, PPI(3)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="586">每個<span style="font-family: "times new roman" , serif;">MPCore</span>中的處理器會以中斷 <span style="font-family: "times new roman" , serif;">ID30</span>作為<span style="font-family: "times new roman" , serif;">Watchdog Timer</span>中斷源<span style="font-family: "times new roman" , serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="196"><span style="font-family: "times new roman" , serif;">A legacy nIRQ pin, PPI(4)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="586">如果選擇<span style="font-family: "times new roman" , serif;">Legacy IRQ mode,</span>就會跳過<span style="font-family: "times new roman" , serif;">Interrupt Distributor</span>直接把中斷發給每個<span style="font-family: "times new roman" , serif;">MPCore</span>處理器<span style="font-family: "times new roman" , serif;">.</span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
反之<span style="font-family: "times new roman" , serif;">,</span>就會藉由<span style="font-family: "times new roman" , serif;">Distributed Interrupt Controller</span>把<span style="font-family: "times new roman" , serif;">IRQ</span>以中斷<span style="font-family: "times new roman" , serif;">ID31</span>發給<span style="font-family: "times new roman" , serif;">MPCore</span>的處理器<span style="font-family: "times new roman" , serif;">.</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="196"><span style="font-family: "times new roman" , serif;">Shared Peripheral Interrupts (SPI)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="586">用以銜接周邊裝置中斷之用<span style="font-family: "times new roman" , serif;">,</span>可設定為<span style="font-family: "times new roman" , serif;">Edge Sensitive (posedge) </span>或 <span style="font-family: "times new roman" , serif;">Level Sensitive(high level),</span>並從中斷編號<span style="font-family: "times new roman" , serif;">ID32</span>開始<span style="font-family: "times new roman" , serif;">.(Interrupt Distributor </span>支援最多<span style="font-family: "times new roman" , serif;">224</span>個中斷源 <span style="font-family: "times new roman" , serif;">)</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Interrupt Distributor </span>的<span style="font-family: "times new roman" , serif;">Prioritization and Selection</span>功能<span style="font-family: "times new roman" , serif;">,</span>會去找出目前最高優先級的<span style="font-family: "times new roman" , serif;">Pending</span>中斷源<span style="font-family: "times new roman" , serif;">(</span>其中<span style="font-family: "times new roman" , serif;">: 0x00</span>為最高優先級<span style="font-family: "times new roman" , serif;">,0x0f</span>為最低優先級<span style="font-family: "times new roman" , serif;">),</span>並將該中斷透過<span style="font-family: "times new roman" , serif;">CPU Interface</span>進行觸發<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Interrupt Distributor </span>會幫每個處理器維護一個尚未處理的中斷列表<span style="font-family: "times new roman" , serif;">,</span>並且選擇最高優先級的中斷發給對應的處理器<span style="font-family: "times new roman" , serif;">,</span>若中斷優先級相同<span style="font-family: "times new roman" , serif;">,</span>則選擇最低的中斷源編號 <span style="font-family: "times new roman" , serif;">(ID0-ID223) </span>進行觸發<span style="font-family: "times new roman" , serif;">. </span>中斷列表中會包括<span style="font-family: "times new roman" , serif;">:</span>優先級<span style="font-family: "times new roman" , serif;">,</span>中斷觸發的目標處理器<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Interrupt Distributor </span>支援<span style="font-family: "times new roman" , serif;">1-N</span>與<span style="font-family: "times new roman" , serif;">N-N</span>兩種中斷模式<span style="font-family: "times new roman" , serif;">,</span>說明如下所示</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="214"></col><col width="569"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="214"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
中斷模式</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="569"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="214"><span style="font-family: "times new roman" , serif;">1-N</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="569">所觸發的中斷可以被任一的處理器清除<span style="font-family: "times new roman" , serif;">,</span>並且其他尚未處理該中斷的處理器對該中斷的狀態也會被清除<span style="font-family: "times new roman" , serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="214"><span style="font-family: "times new roman" , serif;">N-N</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="569">每個處理器對該中斷的處理行為各自獨立<span style="font-family: "times new roman" , serif;">. </span>個別處理器對該中斷的清除<span style="font-family: "times new roman" , serif;">,</span>並不影響到其他尚未處理到該中斷處理器的中斷狀態<span style="font-family: "times new roman" , serif;">.</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>當收到來自處理器發出的 <span style="font-family: "times new roman" , serif;">‘End of Interrupt Information (EOI)’ ,</span>確認對應中斷在處理器已被處理完畢<span style="font-family: "times new roman" , serif;">(Active to Inactive transition),</span>或是通知正在進行處理<span style="font-family: "times new roman" , serif;">(Pending to Active transition), Interrupt Distributor</span>就會改變所維護的中斷清單狀態<span style="font-family: "times new roman" , serif;">. MPCore</span>處理器的中斷可以處於以下三種狀態<span style="font-family: "times new roman" , serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Inactive: </span>該中斷可能尚未被觸發<span style="font-family: "times new roman" , serif;">,</span>或是已經觸發<span style="font-family: "times new roman" , serif;">,</span>並且在該處理器中被處理完畢<span style="font-family: "times new roman" , serif;">.</span>同時<span style="font-family: "times new roman" , serif;">,</span>該中斷源也可能在其他處理器中還處於<span style="font-family: "times new roman" , serif;">Pending</span>或是<span style="font-family: "times new roman" , serif;">Active</span>的狀態<span style="font-family: "times new roman" , serif;">,</span>會根據每個處理器處理中斷的情況而定<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Pending:</span>該中斷已發生<span style="font-family: "times new roman" , serif;">,</span>但尚未在對應處理器中觸發執行<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Active:</span>該中斷已經被執行<span style="font-family: "times new roman" , serif;">,</span>但尚未執行結束<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>當<span style="font-family: "times new roman" , serif;">Interrupt Distributor</span>偵測到中斷發生時<span style="font-family: "times new roman" , serif;">,</span>就會設定對應目標處理器該中斷的狀態為<span style="font-family: "times new roman" , serif;">Pending.</span>如果該中斷為<span style="font-family: "times new roman" , serif;">Level-Sensitive,</span>有任一<span style="font-family: "times new roman" , serif;">MPCore</span>處理器<span style="font-family: "times new roman" , serif;">,</span>對該中斷還處於<span style="font-family: "times new roman" , serif;">Active</span>的狀態時<span style="font-family: "times new roman" , serif;">,</span>則該中斷就不能設定為<span style="font-family: "times new roman" , serif;">Pending. </span>如果是<span style="font-family: "times new roman" , serif;">Edge-Sensitive,</span>當前一個中斷尚未處理完畢<span style="font-family: "times new roman" , serif;">,</span>下一個中斷又發生時<span style="font-family: "times new roman" , serif;">,</span>在<span style="font-family: "times new roman" , serif;">MPCore</span>中<span style="font-family: "times new roman" , serif;">,</span>對不同處理器可能同時存在<span style="font-family: "times new roman" , serif;">Pending</span>與<span style="font-family: "times new roman" , serif;">Active</span>的狀態<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Interrupt Distributor</span>運作的概念<span style="font-family: "times new roman" , serif;">,</span>如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEip43nNeytH4BzyR6aEiss2H387K3CjiXepI3qaaKEEWDPfmHp50y2S5TKDdzj0jWZMFlVyRZ8q_krdFS4Gmxx_OkG8Ft6JYwHZZApnFCbJSPdD3t0Pf0uyr5BuJw0Tl5T8gA6OVm_28ck/s1600/image004%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="549" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEip43nNeytH4BzyR6aEiss2H387K3CjiXepI3qaaKEEWDPfmHp50y2S5TKDdzj0jWZMFlVyRZ8q_krdFS4Gmxx_OkG8Ft6JYwHZZApnFCbJSPdD3t0Pf0uyr5BuJw0Tl5T8gA6OVm_28ck/s1600/image004%255B1%255D.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以透過<span style="font-family: "times new roman" , serif;">Software Generated Interrupt Register </span>或 <span style="font-family: "times new roman" , serif;">Interrupt Set-Pending Register </span>觸發軟體中斷<span style="font-family: "times new roman" , serif;">,</span>給特定或是一組處理器<span style="font-family: "times new roman" , serif;">,Interrupt Distributor</span>對<span style="font-family: "times new roman" , serif;">Hardware</span>與<span style="font-family: "times new roman" , serif;">Software</span>中斷處理的行為完全一致<span style="font-family: "times new roman" , serif;">.</span>只是一個來自硬體<span style="font-family: "times new roman" , serif;">,</span>一個是透過軟體主動觸發的<span style="font-family: "times new roman" , serif;">. </span>軟體中斷可提供在多核心架構下<span style="font-family: "times new roman" , serif;">,</span>跨處理器的中斷通知機制<span style="font-family: "times new roman" , serif;">,</span>包括可以把一個正在<span style="font-family: "times new roman" , serif;">WFI</span>狀態的處理器喚醒<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MPCore</span>每個處理器的<span style="font-family: "times new roman" , serif;">CPU Interface </span>可支援中斷<span style="font-family: "times new roman" , serif;">Priority Masking</span>與<span style="font-family: "times new roman" , serif;">Preempted</span>中斷<span style="font-family: "times new roman" , serif;">(</span>讓高優先級的中斷可以插斷當前的中斷<span style="font-family: "times new roman" , serif;">),</span>一個<span style="font-family: "times new roman" , serif;">Pending</span>中的中斷<span style="font-family: "times new roman" , serif;">,</span>如果通過<span style="font-family: "times new roman" , serif;">Priority Mask,</span>並且優先級高於目前處理器正在執行中的<span style="font-family: "times new roman" , serif;">Active</span>中斷<span style="font-family: "times new roman" , serif;">,</span>就會被該<span style="font-family: "times new roman" , serif;">MPCore</span>處理器插入執行<span style="font-family: "times new roman" , serif;">.</span>當處理器透過<span style="font-family: "times new roman" , serif;">Interrupt Acknowledge Register</span>讀取目前要處理的中斷編號時<span style="font-family: "times new roman" , serif;">,CPU Interface</span>就會記錄該中斷的優先級<span style="font-family: "times new roman" , serif;">,</span>並通知<span style="font-family: "times new roman" , serif;">Interrupt Distributor</span>將該中斷標示為<span style="font-family: "times new roman" , serif;">Active. </span>如果在處理器讀取<span style="font-family: "times new roman" , serif;">Interrupt Acknowledge Register</span>前<span style="font-family: "times new roman" , serif;">,</span>該中斷因為<span style="font-family: "times new roman" , serif;">Priority Mask</span>更改或是透過<span style="font-family: "times new roman" , serif;">Interrupt Pending Clear Register</span>被取消了<span style="font-family: "times new roman" , serif;">,</span>則會從<span style="font-family: "times new roman" , serif;">Interrupt Acknowledge Register</span>讀取到<span style="font-family: "times new roman" , serif;">1023,</span>表示沒有需要被處理的中斷<span style="font-family: "times new roman" , serif;">.</span>當中斷處理完畢<span style="font-family: "times new roman" , serif;">,</span>就會需要處理器設定<span style="font-family: "times new roman" , serif;">End of Interrupt Register,</span>用以透過<span style="font-family: "times new roman" , serif;">CPU Interface</span>通知<span style="font-family: "times new roman" , serif;">Interrupt Distributor</span>將該中斷標示為<span style="font-family: "times new roman" , serif;">Inactive.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<h2 id="14877_cache-coherence%e6%a_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 28px; line-height: 1.3; margin: 1em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<a href="https://www.blogger.com/null" name="Cache_coherence_mechanisms"></a><span style="font-family: "times new roman" , serif;"><span style="font-family: sans-serif , "arial";"><span style="font-size: small;">Cache coherence</span></span></span><span style="font-size: small;">機制</span></h2>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>在<span style="font-family: "times new roman" , serif;">ARM</span>多核心的架構下<span style="font-family: "times new roman" , serif;">,</span>每個處理器都會有自己的<span style="font-family: "times new roman" , serif;">L1 Cache,</span>並共用同一塊<span style="font-family: "times new roman" , serif;">L2 Cache,</span>也因為如此<span style="font-family: "times new roman" , serif;">,</span>當兩個處理器的<span style="font-family: "times new roman" , serif;">Cache</span>有暫存到同一個位址的記憶體資料時<span style="font-family: "times new roman" , serif;">,</span>如果沒有一個協同確認機制的就有機會導致某個處理器對同一個位址的資料做了修改<span style="font-family: "times new roman" , serif;">,</span>但是另一個處理器上讀出的卻是尚未修改過的內容<span style="font-family: "times new roman" , serif;">,</span>如此就會導致系統潛藏的錯誤問題<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">ARM</span>多核心架構下採用的是<span style="font-family: "times new roman" , serif;">Tightly Coupled Memory,</span>所有的處理器會共享同一塊外部記憶體<span style="font-family: "times new roman" , serif;">,</span>可以更自進行工作安排<span style="font-family: "times new roman" , serif;">,</span>由於各自的處理器有自己的<span style="font-family: "times new roman" , serif;">L1 Cache</span>與共享的<span style="font-family: "times new roman" , serif;">L2 Cache,</span>也因此<span style="font-family: "times new roman" , serif;">,</span>外部記憶體<span style="font-family: "times new roman" , serif;">,L2</span>與各處理器中的<span style="font-family: "times new roman" , serif;">L1 Cache Coherency</span>就會變得重要<span style="font-family: "times new roman" , serif;">.(Loosely-coupled </span>各處理器就不會共享同一塊外部記憶體<span style="font-family: "times new roman" , serif;">,</span>各處理單元可透過<span style="font-family: "times new roman" , serif;">Message-Passing</span>機制進行溝通<span style="font-family: "times new roman" , serif;">)</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Cache Coherence </span>主要會同步每個處理器<span style="font-family: "times new roman" , serif;">L1</span>與<span style="font-family: "times new roman" , serif;">L2</span>的<span style="font-family: "times new roman" , serif;">Cache,</span>如果有處理器更新到另一個處理器<span style="font-family: "times new roman" , serif;">Cache</span>中也有同位址的資料內容時<span style="font-family: "times new roman" , serif;">,</span>就會透過這機制把有同位址資料的處理器<span style="font-family: "times new roman" , serif;">Cache</span>進行更新<span style="font-family: "times new roman" , serif;">,</span>參考有關<span style="font-family: "times new roman" , serif;">Cache Coherence</span>的資訊例如<span style="font-family: "times new roman" , serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Cache_coherency" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/Cache_coherency</a></span></span> .</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">ARM</span>所採用的<span style="font-family: "times new roman" , serif;">Snooping Control Unit</span>主要行為為會監控個別處理器<span style="font-family: "times new roman" , serif;">Cache </span>存取資料的位址<span style="font-family: "times new roman" , serif;">,</span>如果有一個寫入的動作發生在其他<span style="font-family: "times new roman" , serif;">Cache</span>也有複製到的位址的資料<span style="font-family: "times new roman" , serif;">,Cache Controller</span>就會把該監控的記憶體位置設定為失效<span style="font-family: "times new roman" , serif;">. Snooping Protocol</span>優點為<span style="font-family: "times new roman" , serif;">,</span>速度快<span style="font-family: "times new roman" , serif;">,</span>由與所有的<span style="font-family: "times new roman" , serif;">Request/Response Transaction</span>都會<span style="font-family: "times new roman" , serif;">Broadcast</span>到系統中所有單元<span style="font-family: "times new roman" , serif;">,</span>被所有的處理器監控到<span style="font-family: "times new roman" , serif;">,</span>缺點就是<span style="font-family: "times new roman" , serif;">Snooping Protocol</span>不適合更大型的多核新處理器架構<span style="font-family: "times new roman" , serif;">,</span>要不就是必須提高<span style="font-family: "times new roman" , serif;">Bus</span>的<span style="font-family: "times new roman" , serif;">Bandwidth.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>其它的作法還包括<span style="font-family: "times new roman" , serif;">Directory-Based Coherence,</span>這是一個目錄式的架構<span style="font-family: "times new roman" , serif;">,</span>屬於每個<span style="font-family: "times new roman" , serif;">Cache</span>所共同使用到的資料會被放置在一個共通的目錄下<span style="font-family: "times new roman" , serif;">,</span>這個目錄工作行為就像是一個過濾器<span style="font-family: "times new roman" , serif;">,</span>處理器必須要透過該機制才可以把資料從外部記憶體載入到自己的<span style="font-family: "times new roman" , serif;">Cache</span>中<span style="font-family: "times new roman" , serif;">. </span>如果該共享的資料被改變了<span style="font-family: "times new roman" , serif;">,</span>目錄內容就會同步更新<span style="font-family: "times new roman" , serif;">,</span>或是會把相關<span style="font-family: "times new roman" , serif;">Cache</span>中的資料設定為失效<span style="font-family: "times new roman" , serif;">.</span>缺點就是<span style="font-family: "times new roman" , serif;">,</span>資料的取得會有比較長的延遲 <span style="font-family: "times new roman" , serif;">(</span>必須有 <span style="font-family: "times new roman" , serif;">3 hop</span>流程 <span style="font-family: "times new roman" , serif;">Request/Respond/Forward),</span>好處是<span style="font-family: "times new roman" , serif;">Transaction</span>過程<span style="font-family: "times new roman" , serif;">,</span>只需要跟<span style="font-family: "times new roman" , serif;">Directory-based Controller</span>同步就好<span style="font-family: "times new roman" , serif;">,</span>不需要對系統中所有的單元<span style="font-family: "times new roman" , serif;">Broadcast. </span>一般來說<span style="font-family: "times new roman" , serif;">,</span>超過<span style="font-family: "times new roman" , serif;">64</span>個處理器單元的架構<span style="font-family: "times new roman" , serif;">,</span>就會採用<span style="font-family: "times new roman" , serif;">Directory-based.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>Snoop Control </strong></span><span style="font-size: small;"><strong>Unit</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">SCU </span>主要用以連結<span style="font-family: "times new roman" , serif;">1-4</span>個<span style="font-family: "times new roman" , serif;">MPCore</span>處理器<span style="font-family: "times new roman" , serif;">,</span>透過<span style="font-family: "times new roman" , serif;">AXI Bus</span>去存取<span style="font-family: "times new roman" , serif;">Memory system,</span>主要功能包括</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">1,</span>同步每個<span style="font-family: "times new roman" , serif;">MPCore</span>處理器的<span style="font-family: "times new roman" , serif;">Data Cache</span>內容 <span style="font-family: "times new roman" , serif;"><span style="color: red;"><span style="text-decoration-line: underline;"><strong>(</strong></span></span></span><span style="color: red;"><span style="text-decoration-line: underline;"><strong>不包括</strong><span style="font-family: "times new roman" , serif;"><strong>Instruction Cache</strong></span></span></span><span style="color: red;"><span style="text-decoration-line: underline;"><strong>的同步</strong><span style="font-family: "times new roman" , serif;"><strong>)</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">2,</span>初始化<span style="font-family: "times new roman" , serif;">L2 Cache</span>與<span style="font-family: "times new roman" , serif;">AXI Memory Access</span>的行為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">3,</span>仲裁每個<span style="font-family: "times new roman" , serif;">MPCore</span>處理器對<span style="font-family: "times new roman" , serif;">L2 Cache</span>的存取行為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">4,</span>管理<span style="font-family: "times new roman" , serif;">ACP(Accelerator Coherency Port)</span>介面的存取</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">ACP(Accelerator Coherency Port)</span>主要用於連接原本不被處理器<span style="font-family: "times new roman" , serif;">Cache</span>管理的<span style="font-family: "times new roman" , serif;">AXI Master</span>週邊<span style="font-family: "times new roman" , serif;">,</span>例如<span style="font-family: "times new roman" , serif;">:DMA Engine. </span>過往的設計中<span style="font-family: "times new roman" , serif;">,</span>如果有一塊記憶體是會被硬體<span style="font-family: "times new roman" , serif;">DMA</span>直接更動內容<span style="font-family: "times new roman" , serif;">,</span>則該記憶體我們就會設定為<span style="font-family: "times new roman" , serif;">non-Cached,</span>以避免因為處理器的<span style="font-family: "times new roman" , serif;">Cache</span>把該記憶體內容暫存<span style="font-family: "times new roman" , serif;">,</span>但該記憶體內容在外部記憶體中卻已經被硬體修改了<span style="font-family: "times new roman" , serif;">,</span>導致兩者不一致的執行正確性問題<span style="font-family: "times new roman" , serif;">. </span>為了規避這問題<span style="font-family: "times new roman" , serif;">,</span>選擇把對應記憶體的<span style="font-family: "times new roman" , serif;">Cache</span>關閉<span style="font-family: "times new roman" , serif;">,</span>帶來的缺點就是處理器必須去等待外部相對<span style="font-family: "times new roman" , serif;">Cache</span>而言較慢速的記憶體進行資料的存取<span style="font-family: "times new roman" , serif;">,</span>導致效能上的減損<span style="font-family: "times new roman" , serif;">. </span>也因此<span style="font-family: "times new roman" , serif;">,</span>透過<span style="font-family: "times new roman" , serif;">SCU</span>上的<span style="font-family: "times new roman" , serif;">ACP,</span>就可以讓硬體<span style="font-family: "times new roman" , serif;">DMA</span>更動資料內容時與處理器內部的<span style="font-family: "times new roman" , serif;">Cache</span>保持一致性<span style="font-family: "times new roman" , serif;">,</span>就算硬體<span style="font-family: "times new roman" , serif;">DMA</span>要更動對應記憶體位址的內容<span style="font-family: "times new roman" , serif;">,</span>基於<span style="font-family: "times new roman" , serif;">ACP</span>的同步機制<span style="font-family: "times new roman" , serif;">,</span>就可以在開啟處理器<span style="font-family: "times new roman" , serif;">Cache</span>的狀態下<span style="font-family: "times new roman" , serif;">,</span>確保<span style="font-family: "times new roman" , serif;">Cache</span>內容被更新到<span style="font-family: "times new roman" , serif;">,</span>讓整體運作效能維持在高檔<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">ACP</span>主要目的為讓其它裝置也可以共享並存取<span style="font-family: "times new roman" , serif;">L1/L2 Cache</span>中的資料內容<span style="font-family: "times new roman" , serif;">,</span>以期可以在不增加系統功耗的情況下<span style="font-family: "times new roman" , serif;">(</span>減少到外部記憶體存取的次數<span style="font-family: "times new roman" , serif;">)</span>增加系統效能<span style="font-family: "times new roman" , serif;">. ACP</span>裝置<span style="font-family: "times new roman" , serif;">Read/Write</span>的行為如下所示</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 804px;"><colgroup><col width="129"></col><col width="653"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "times new roman" , serif;">READ</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="653"><span style="font-family: "times new roman" , serif;">ACP</span>上的裝置<span style="font-family: "times new roman" , serif;">,</span>要進行<span style="font-family: "times new roman" , serif;">Read</span>動作時<span style="font-family: "times new roman" , serif;">,</span>會先確認資料是否有在<span style="font-family: "times new roman" , serif;">L1 Cahce,</span>反之<span style="font-family: "times new roman" , serif;">,</span>則確認是否有在<span style="font-family: "times new roman" , serif;">L2 Cache</span>中<span style="font-family: "times new roman" , serif;">,</span>最後才是從外部記憶體中取得<span style="font-family: "times new roman" , serif;">,</span>也就是說如果資料有在<span style="font-family: "times new roman" , serif;">L1</span>或是<span style="font-family: "times new roman" , serif;">L2 Cache</span>中<span style="font-family: "times new roman" , serif;">,ACP</span>上的裝置會直接從<span style="font-family: "times new roman" , serif;">Cache</span>中抓取資料<span style="font-family: "times new roman" , serif;">,</span>加速運作的效率</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "times new roman" , serif;">WRITE</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="653"><span style="font-family: "times new roman" , serif;">ACP</span>上的裝置<span style="font-family: "times new roman" , serif;">,</span>要進行<span style="font-family: "times new roman" , serif;">Write</span>動作時<span style="font-family: "times new roman" , serif;">,</span>會確認<span style="font-family: "times new roman" , serif;">L1 Cache</span>中是否有暫存同一位址的資料<span style="font-family: "times new roman" , serif;">,</span>若有<span style="font-family: "times new roman" , serif;">,</span>會<span style="font-family: "times new roman" , serif;">Invalidate L1</span>上的資料<span style="font-family: "times new roman" , serif;">,</span>並把該筆更新的資料內容配置到<span style="font-family: "times new roman" , serif;">L2 Cache</span>中<span style="font-family: "times new roman" , serif;">.</span></td></tr>
</tbody></table>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>WatchDog Reset</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>在系統設計時<span style="font-family: "times new roman" , serif;">,</span>為了避免軟體遇到無法<span style="font-family: "times new roman" , serif;">Recovery</span>的錯誤<span style="font-family: "times new roman" , serif;">,WatchDog</span>會是系統最後一到防線<span style="font-family: "times new roman" , serif;">,</span>而在<span style="font-family: "times new roman" , serif;">MPCore</span>架構下<span style="font-family: "times new roman" , serif;">,</span>每個處理器都有自己的<span style="font-family: "times new roman" , serif;">WatchDog Counter,</span>一旦該<span style="font-family: "times new roman" , serif;">Counter</span>太久沒有被踢到<span style="font-family: "times new roman" , serif;">,</span>導致<span style="font-family: "times new roman" , serif;">Counter</span>倒數為<span style="font-family: "times new roman" , serif;">0,</span>就會觸發<span style="font-family: "times new roman" , serif;">Reset</span>的機制<span style="font-family: "times new roman" , serif;">.</span>目前<span style="font-family: "times new roman" , serif;">MPCore</span>提供的<span style="font-family: "times new roman" , serif;">Reset</span>設定包括 <span style="font-family: "times new roman" , serif;">(</span>所有的設定都為 <span style="font-family: "times new roman" , serif;">Active LOW)</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 804px;"><colgroup><col width="177"></col><col width="606"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">名稱</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="606"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">說明</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">nSCURESET</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="606"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">用以</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Reset MPCore Processor Logic,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">但並不包括個別</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MPCore CPU Logic</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">nCPURESET[3:0]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="606"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">用以</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Reset</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">目標</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MPCore CPU Logic (</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">但不包括</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">CP14 Debug Logic)</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">nWDRESET[3:0]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="606"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">用以</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Reset WatchDog Reset Status Flag,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">但如果這次系統</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Reset,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">是由特定處理器的</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">WatchDog Reset</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">所觸發</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">則對應的</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Status Flag</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">就不會被重置</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">.</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">nNEONRESET[3:0]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="606"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">DBGnTRST</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="606"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">用以進行</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">DBGTAP reset</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">nDBGRESET[3:0]</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">or</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">nPORESET[3:0]</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="606"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">用以在</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">PowerOn Reset</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">初始化</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">CP14 Debug Logic</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">RESETREQ[3:0]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="606"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">可針對目標處理器或是所有的處理器</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">觸發</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Reset</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">流程</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">. </span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">被用在</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">WatchDog</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">倒數為</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">0</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">時觸發</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">.</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;"></span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">基於上述的設定選項</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">參考</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Cortex A9 MPCore</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">文件</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">,Reset</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">總共可以包括以下的組合</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">其中包括整個</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MPCore</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">的</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Reset,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">或是針對個別</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">CPU Logic,</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">以及針對</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Debug</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">與</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">WatchDog Status Flag</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">的動作</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">.</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 804px;"><colgroup><col width="123"></col><col width="124"></col><col width="124"></col><col width="124"></col><col width="124"></col><col width="124"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">nSCURESET and nPERIPHRESET</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">nCPURESET[3:0]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">nNEONRESET[3:0]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">nDBGRESET[3:0]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">nWDRESET[3:0]</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Cortex-A9 MPCore</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power on reset</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 0</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Cortex-A9 MPCore</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Software reset</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">(CP14 Debug Logic </span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">不做</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Reset)</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 0</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Per processor</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power on reset</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0 or All 1</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Per processor</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Software reset</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0 or All 1</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">SIMD MPE</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">power on</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Cortex-A9 MPCore</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Debug</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Per processor</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Debug</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Per processor</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Watchdog flag</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">All 1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">[n]=0</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>當作業系統核心遇到無法修復的錯誤時<span style="font-family: "times new roman" , serif;">,</span>選擇 <span style="font-family: "times new roman" , serif;">MPCore Power on reset</span>讓系統重置<span style="font-family: "times new roman" , serif;">,</span>會是比較好的選擇<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>Power Management</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>消費性電子最重要的感受就是功耗<span style="font-family: "times new roman" , serif;">,ARM MPCore</span>處理器同樣提供了<span style="font-family: "times new roman" , serif;">Run/Standby/Dormany/Shutdown</span>四種電源模式<span style="font-family: "times new roman" , serif;">,</span>如下表所示<span style="font-family: "times new roman" , serif;">,Wake-Up</span>速度最快的省電模式是<span style="font-family: "times new roman" , serif;">Standby Mode,</span>此時處理器的<span style="font-family: "times new roman" , serif;">Logic</span>並沒有斷電<span style="font-family: "times new roman" , serif;">,</span>相關暫存器與<span style="font-family: "times new roman" , serif;">CoProcessor</span>的狀態都維持住<span style="font-family: "times new roman" , serif;">,</span>只有處理器進入<span style="font-family: "times new roman" , serif;">Clock Gating</span>的狀態<span style="font-family: "times new roman" , serif;">. </span>若希望包括處理器<span style="font-family: "times new roman" , serif;">Logic</span>也斷電<span style="font-family: "times new roman" , serif;">,</span>則進一步把相關狀態暫存到處理器<span style="font-family: "times new roman" , serif;">TCM</span>中<span style="font-family: "times new roman" , serif;">,</span>若<span style="font-family: "times new roman" , serif;">Leakage Current</span>過高<span style="font-family: "times new roman" , serif;">,</span>也可採用<span style="font-family: "times new roman" , serif;">Shutdown</span>模式<span style="font-family: "times new roman" , serif;">,</span>但把記憶體與狀態回存到<span style="font-family: "times new roman" , serif;">Storage</span>上<span style="font-family: "times new roman" , serif;">,</span>在下次<span style="font-family: "times new roman" , serif;">Wake-Up</span>時<span style="font-family: "times new roman" , serif;">,</span>重新回復系統的正常執行<span style="font-family: "times new roman" , serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 804px;"><colgroup><col width="83"></col><col width="190"></col><col width="146"></col><col width="343"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Mode</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Cortex Processor Logic</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="146"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">OnChip RAM</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Wake-Up</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Run</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power Up </span></span><span style="font-size: xx-small;">並且所有</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Logic</span></span><span style="font-size: xx-small;">都有</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Clock </span></span><span style="font-size: xx-small;">輸入</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="146"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power Up</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Standby</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power Up</span></span><span style="font-size: xx-small;">但除了</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Wake-Up Logic</span></span><span style="font-size: xx-small;">外</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">是處於</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Clock Gating</span></span><span style="font-size: xx-small;">的狀態</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="146"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power Up</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"><span style="font-size: xx-small;">此時外部記憶體會進入</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Low-Power Mode,ARM CPU</span></span><span style="font-size: xx-small;">會處於</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">WFI (Wait For Interrupt)</span></span><span style="font-size: xx-small;">或</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">WFE(Wait For Event)</span></span><span style="font-size: xx-small;">狀態</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">當處理器有收到中斷觸發</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,Debug Request….etc</span></span><span style="font-size: xx-small;">時</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">就會立刻喚醒</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">.</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: xx-small;">通常要看</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">SoC</span></span><span style="font-size: xx-small;">本身的</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Leakage Current,</span></span><span style="font-size: xx-small;">會決定在這狀態下底電流的消耗情況</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">.</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Dormant</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">(</span></span><span style="font-size: xx-small;">最省電的待機狀態</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">)</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power Off</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="146"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Retention state/voltage</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"><span style="font-size: xx-small;">外部記憶體會進入</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Low-Power Mode.</span></span><span style="font-size: xx-small;">中斷會透過硬體</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Wake-Up Module</span></span><span style="font-size: xx-small;">讓處理器</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power On,</span></span><span style="font-size: xx-small;">此時處理器要重新初始化</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">在進入</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Dormant Mode</span></span><span style="font-size: xx-small;">前處理器的暫存器與相關狀態會儲存在</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">OnChip RAM</span></span><span style="font-size: xx-small;">上</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">通常會透過一個</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">32bits Register</span></span><span style="font-size: xx-small;">記住在</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">OnChip RAM</span></span><span style="font-size: xx-small;">上</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">WakeUp</span></span><span style="font-size: xx-small;">後要執行的程式碼記憶體位址</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">以便醒來後</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">跳過去執行</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">恢復進入</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Dormant Mode</span></span><span style="font-size: xx-small;">前的運作狀態</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">.</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Shutdown</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power Off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="146"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Power Off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"><span style="font-size: xx-small;">執行完整重新開機的流程</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">.</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>以<span style="font-family: "times new roman" , serif;">cortex A9 MPCore</span>四核心的架構來說<span style="font-family: "times new roman" , serif;">,</span>總共可以分出<span style="font-family: "times new roman" , serif;">14</span>個<span style="font-family: "times new roman" , serif;">Power Domain,</span>包括<span style="font-family: "times new roman" , serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">1,</span>針對四個<span style="font-family: "times new roman" , serif;">Cortex A9 Processor</span>的<span style="font-family: "times new roman" , serif;">Power Domain (4)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">2,</span>針對四個<span style="font-family: "times new roman" , serif;">Cortex A9 Processor Data Engine</span>的<span style="font-family: "times new roman" , serif;">Power Domain (4)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">3,</span>針對四個<span style="font-family: "times new roman" , serif;">Cortex A9 Processor Cache</span>與<span style="font-family: "times new roman" , serif;">TLB OnChip RAM</span>的<span style="font-family: "times new roman" , serif;">Power Domain (4)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">4,</span>一個供<span style="font-family: "times new roman" , serif;">SCU(Snoop Control Unit) duplicated TAG RAMs</span>的<span style="font-family: "times new roman" , serif;">Power Domain (1)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">5,</span>一個其它<span style="font-family: "times new roman" , serif;">Logc(</span>例如<span style="font-family: "times new roman" , serif;">:SCU Logic,Private Peripherals..etc)</span>的<span style="font-family: "times new roman" , serif;">Power Domain (1)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>上述<span style="font-family: "times new roman" , serif;">Power Domain</span>並不包括<span style="font-family: "times new roman" , serif;">SoC</span>中其它週邊的<span style="font-family: "times new roman" , serif;">Power Domain(</span>例如<span style="font-family: "times new roman" , serif;">:USB Phy/Logic,Storage..etc),</span>如果要達到最佳省電效益的話<span style="font-family: "times new roman" , serif;">,</span>就必須要考慮相關應用的軟體行為<span style="font-family: "times new roman" , serif;">,</span>搭配對應的<span style="font-family: "times new roman" , serif;">PMIC(Power Management IC)</span>的<span style="font-family: "times new roman" , serif;">Power Group</span>來做區分<span style="font-family: "times new roman" , serif;">,</span>維持系統中只有必須的處理器與週邊是<span style="font-family: "times new roman" , serif;">Power On</span>與有<span style="font-family: "times new roman" , serif;">Clock Input</span>的狀態<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>若系統的<span style="font-family: "times new roman" , serif;">Standby </span>或<span style="font-family: "times new roman" , serif;">Dormant Current</span>夠低<span style="font-family: "times new roman" , serif;">,</span>在實際的<span style="font-family: "times new roman" , serif;">Android</span>手機上<span style="font-family: "times new roman" , serif;">,</span>也有快開<span style="font-family: "times new roman" , serif;">(Fast-Boot)</span>機制是透過這類機制設計的<span style="font-family: "times new roman" , serif;">,</span>讓系統不需要真的走到<span style="font-family: "times new roman" , serif;">Shutdown</span>模式<span style="font-family: "times new roman" , serif;">,</span>而在下次開機時<span style="font-family: "times new roman" , serif;">,</span>又可以非常快的回復到正常運作的模式下<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>記憶體管理系統</strong></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MMU(Memory Management Unit)</span>主要是負責把虛擬記憶體位址<span style="font-family: "times new roman" , serif;">(32-bits </span>為 <span style="font-family: "times new roman" , serif;">0-4GB)</span>對應到實體記憶體中<span style="font-family: "times new roman" , serif;">,</span>而在<span style="font-family: "times new roman" , serif;">ARM</span>的架構下負責這層對應機制的就是<span style="font-family: "times new roman" , serif;">TLB(Translation Lookaside Buffer). </span>參考<span style="font-family: "times new roman" , serif;">ARM</span>的<span style="font-family: "times new roman" , serif;">Technical Reference Manual,</span>在<span style="font-family: "times new roman" , serif;">ARM9</span>下<span style="font-family: "times new roman" , serif;">,MMU</span>可以支援<span style="font-family: "times new roman" , serif;">1MB(Section),64KB(Large Page),4KB(Small Page)</span>與<span style="font-family: "times new roman" , serif;">1KB(Tiny Page)</span>四種分頁的大小<span style="font-family: "times new roman" , serif;">,</span>不過在<span style="font-family: "times new roman" , serif;">ARM11</span>與<span style="font-family: "times new roman" , serif;">Cortex</span>時<span style="font-family: "times new roman" , serif;">,</span>對應的<span style="font-family: "times new roman" , serif;">Mapping Size</span>變為<span style="font-family: "times new roman" , serif;">4KB, 64KB, 1MB</span>與<span style="font-family: "times new roman" , serif;">16MB(Super Section),</span>其中<span style="font-family: "times new roman" , serif;">1KB</span>的分頁已經不存在了<span style="font-family: "times new roman" , serif;">(</span>應該也是因應目前<span style="font-family: "times new roman" , serif;">Application Processor</span>記憶體的實際配置也較大<span style="font-family: "times new roman" , serif;">),</span>對分頁與實體記憶體的對應<span style="font-family: "times new roman" , serif;">,</span>舉以下例子來說明<span style="font-family: "times new roman" , serif;">:</span>使用者在虛擬記憶體位址所使用到的<span style="font-family: "times new roman" , serif;">4KB Page,</span>在實體記憶體中就會是連續的實體記憶體區塊<span style="font-family: "times new roman" , serif;">,</span>但如果是兩個在虛擬記憶體中連續的<span style="font-family: "times new roman" , serif;">4KB Pages,</span>在實體記憶體中就有可能是分離的兩塊實體記憶體區塊<span style="font-family: "times new roman" , serif;">,</span>只是因為透過硬體<span style="font-family: "times new roman" , serif;">MMU TLB</span>的配置<span style="font-family: "times new roman" , serif;">,</span>在虛擬記憶體空間中<span style="font-family: "times new roman" , serif;">,</span>應用程式的執行與使用會當成是兩個連續的記憶體區塊<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MMU</span>對多工環境尤其重要<span style="font-family: "times new roman" , serif;">,</span>例如在<span style="font-family: "times new roman" , serif;">Linux</span>環境中<span style="font-family: "times new roman" , serif;">,</span>每個<span style="font-family: "times new roman" , serif;">Task</span>都會在自己的虛擬記憶體空間中對應到一組共用的共享函式庫<span style="font-family: "times new roman" , serif;">,</span>這些共享函式庫就可以透過<span style="font-family: "times new roman" , serif;">MMU</span>把每個<span style="font-family: "times new roman" , serif;">Task</span>共用的共享函式內容<span style="font-family: "times new roman" , serif;">,</span>用同一塊實體記憶體對應到每個<span style="font-family: "times new roman" , serif;">Task</span>各自的虛擬記憶體空間中<span style="font-family: "times new roman" , serif;">,</span>如此雖然系統中有多個<span style="font-family: "times new roman" , serif;">Task</span>同時運作<span style="font-family: "times new roman" , serif;">,</span>但每個<span style="font-family: "times new roman" , serif;">Task</span>所共用的記憶體內容部分就可以透過<span style="font-family: "times new roman" , serif;">MMU</span>支援對應到同一塊實體記憶體中<span style="font-family: "times new roman" , serif;">,</span>減少<span style="font-family: "times new roman" , serif;">Run-Time</span>的實體記憶體需求<span style="font-family: "times new roman" , serif;">.</span>另一個例子就是<span style="font-family: "times new roman" , serif;">,Android Dalvik</span>的<span style="font-family: "times new roman" , serif;">Java</span>應用<span style="font-family: "times new roman" , serif;">,</span>每個<span style="font-family: "times new roman" , serif;">MMI</span>的應用程式都會基於一個<span style="font-family: "times new roman" , serif;">Dalvik VM</span>運作<span style="font-family: "times new roman" , serif;">,</span>同時每個<span style="font-family: "times new roman" , serif;">VM</span>也都會載入相關動態函式庫<span style="font-family: "times new roman" , serif;">.so/.jar,</span>基於<span style="font-family: "times new roman" , serif;">MMU</span>的機制<span style="font-family: "times new roman" , serif;">,</span>雖然是每個<span style="font-family: "times new roman" , serif;">MMI</span>應用都基於一個<span style="font-family: "times new roman" , serif;">Dalvik VM,</span>但實際上共用的部份就會透過虛擬記憶體分頁配置對應到同一塊實體記憶體中<span style="font-family: "times new roman" , serif;">,</span>降低實際的記憶體需求<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MMU</span>也可以把記憶體範圍依據<span style="font-family: "times new roman" , serif;">User Mode</span>與<span style="font-family: "times new roman" , serif;">Kernel Mode</span>設定不同的權限<span style="font-family: "times new roman" , serif;">,</span>像是<span style="font-family: "times new roman" , serif;">Non-Access,Read Only,Read/Write,</span>如果有發生違反權限的存取行為時<span style="font-family: "times new roman" , serif;">,</span>就會導致<span style="font-family: "times new roman" , serif;">ARM</span>觸發<span style="font-family: "times new roman" , serif;">Abort</span>例外<span style="font-family: "times new roman" , serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>在<span style="font-family: "times new roman" , serif;">ARM</span>平台上<span style="font-family: "times new roman" , serif;">,</span>負責查表由虛擬記憶體對應到實體記憶體的動作是由硬體<span style="font-family: "times new roman" , serif;">TLB</span>機制來實現的<span style="font-family: "times new roman" , serif;">,</span>在單一<span style="font-family: "times new roman" , serif;">ARM</span>處理器的架構下<span style="font-family: "times new roman" , serif;">,</span>通常只有一個<span style="font-family: "times new roman" , serif;">TLB</span>分頁配置位址<span style="font-family: "times new roman" , serif;">,</span>也就是說目前<span style="font-family: "times new roman" , serif;">Task Context-Switch</span>到<span style="font-family: "times new roman" , serif;">Task #A</span>就會把該<span style="font-family: "times new roman" , serif;">Task</span>的<span style="font-family: "times new roman" , serif;">TLB </span>分頁配置位址載入<span style="font-family: "times new roman" , serif;">,</span>如果是又切換到<span style="font-family: "times new roman" , serif;">Task #B</span>就會載入該<span style="font-family: "times new roman" , serif;">Task</span>的<span style="font-family: "times new roman" , serif;">TLB </span>分頁配置位址<span style="font-family: "times new roman" , serif;">.</span>單核心的架構下<span style="font-family: "times new roman" , serif;">,</span>同一時間處理器只會處理一個<span style="font-family: "times new roman" , serif;">Task,</span>因此<span style="font-family: "times new roman" , serif;">TLB</span>的配置只需要符合這樣的行為即可<span style="font-family: "times new roman" , serif;">. </span>如下圖所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHXZydVYs-vUzmAFIVT-Ic0LsNCVN0EEfM14RfAtOsurRSDOROyJlrkyFtJP74XjSjHSztEDmCixL3Q00h-yOSTXEccty3kuwyWrEcb9YDUcYAMawrXi8z_sgU1N27uvjLc6hzpfTIxh4/s1600/image006%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="604" data-original-width="801" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHXZydVYs-vUzmAFIVT-Ic0LsNCVN0EEfM14RfAtOsurRSDOROyJlrkyFtJP74XjSjHSztEDmCixL3Q00h-yOSTXEccty3kuwyWrEcb9YDUcYAMawrXi8z_sgU1N27uvjLc6hzpfTIxh4/s1600/image006%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然而<span style="font-family: "times new roman" , serif;">,</span>在多核心的架構下<span style="font-family: "times new roman" , serif;">,</span>同一時間會有多個<span style="font-family: "times new roman" , serif;">Task</span>被執行<span style="font-family: "times new roman" , serif;">,</span>因此會在每個核心都提供<span style="font-family: "times new roman" , serif;">Micro TLB,</span>用以載入目前該核心正在執行中的<span style="font-family: "times new roman" , serif;">Task TLB</span>記憶體分頁<span style="font-family: "times new roman" , serif;">,</span>並且整個系統會有一組<span style="font-family: "times new roman" , serif;">Main TLB,</span>用以同步每個處理器<span style="font-family: "times new roman" , serif;">Micro TLB</span>共用的部份<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>以<span style="font-family: "times new roman" , serif;">ARMv7</span>架構為例<span style="font-family: "times new roman" , serif;">,</span>要控制<span style="font-family: "times new roman" , serif;">TLB Translation Table,</span>可以透過<span style="font-family: "times new roman" , serif;">CP15</span>的暫存器<span style="font-family: "times new roman" , serif;">c2,</span>其中<span style="font-family: "times new roman" , serif;">c2</span>主要提供以下<span style="font-family: "times new roman" , serif;">Translation table base registers</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 807px;"><colgroup><col width="182"></col><col width="603"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
名稱</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="603"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Translation Table Base Register 0 (TTBR0)</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="603">用來記錄<span style="font-family: "times new roman" , serif;">User-Mode</span>應用<span style="font-family: "times new roman" , serif;">Task</span>的記憶體分頁架構所在的<span style="font-family: "times new roman" , serif;">Base Address,</span>通常大小為<span style="font-family: "times new roman" , serif;">128bytes</span>到<span style="font-family: "times new roman" , serif;">16kbytes (</span>也就是說每個<span style="font-family: "times new roman" , serif;">Task</span>的 <span style="font-family: "times new roman" , serif;">1<sup>st</sup> Level Table</span>可以有<span style="font-family: "times new roman" , serif;">32</span>到<span style="font-family: "times new roman" , serif;">4k</span>筆<span style="font-family: "times new roman" , serif;">Items(</span>也就是 <span style="font-family: "times new roman" , serif;">1<sup>st</sup> Level Table Index</span>的最大長度<span style="font-family: "times new roman" , serif;">),</span>可透過<span style="font-family: "times new roman" , serif;">TTBCR.N</span>值決定<span style="font-family: "times new roman" , serif;">),</span>當作業系統進行<span style="font-family: "times new roman" , serif;">Context Switch</span>時<span style="font-family: "times new roman" , serif;">,</span>會把這個暫存器的值<span style="font-family: "times new roman" , serif;">,</span>指到新的<span style="font-family: "times new roman" , serif;">Task</span>的記憶體分頁架構的<span style="font-family: "times new roman" , serif;">Base Address,</span>並更新<span style="font-family: "times new roman" , serif;">TTBCR</span>與<span style="font-family: "times new roman" , serif;">CONTEXTIDR</span>暫存器<span style="font-family: "times new roman" , serif;">.</span>如果<span style="font-family: "times new roman" , serif;">TTBCR</span>設定為<span style="font-family: "times new roman" , serif;">0,</span>則以<span style="font-family: "times new roman" , serif;">ARMv6</span>以前的架構來操作 <span style="font-family: "times new roman" , serif;">TTBR0.(</span>也就是說只有一個 <span style="font-family: "times new roman" , serif;">TTBR,User-Mode</span>與<span style="font-family: "times new roman" , serif;">Kernel-Mode</span>的記憶體分頁都透過它描述<span style="font-family: "times new roman" , serif;">,</span>相對的當<span style="font-family: "times new roman" , serif;">Context-Switch</span>發生時<span style="font-family: "times new roman" , serif;">,</span>就缺少分出<span style="font-family: "times new roman" , serif;">TTBR0</span>與 <span style="font-family: "times new roman" , serif;">TTBR1</span>的彈性<span style="font-family: "times new roman" , serif;">).</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Translation Table Base Register 1 (TTBR1)</span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="603">用來記錄作業系統特權等級與<span style="font-family: "times new roman" , serif;">I/O</span>空間的記憶體分頁架構所在的<span style="font-family: "times new roman" , serif;">Base Address,</span>屬於這類的記憶體規劃<span style="font-family: "times new roman" , serif;">,</span>並不會隨著應用<span style="font-family: "times new roman" , serif;">Task Context-Switch</span>而改變<span style="font-family: "times new roman" , serif;">.</span>通常這<span style="font-family: "times new roman" , serif;">Table</span>大小都為<span style="font-family: "times new roman" , serif;">16Kbytes. (</span>就是說 <span style="font-family: "times new roman" , serif;">1<sup>st</sup> Level Table</span>可以有最多 <span style="font-family: "times new roman" , serif;">4k</span>筆<span style="font-family: "times new roman" , serif;">Items(= 1<sup>st</sup> Level Table Index</span>的最大長度<span style="font-family: "times new roman" , serif;">)).</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Translation Table Base Control Register (TTBCR)</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="603">在沒有 <span style="font-family: "times new roman" , serif;">Trust Zone Security Extensions</span>支援的環境下<span style="font-family: "times new roman" , serif;">,</span>對應的欄位如下所示<br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 605px;"><colgroup><col width="534"></col><col width="48"></col></colgroup><tbody>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="534"><span style="font-family: "times new roman" , serif;">31 – 3</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="48"><span style="font-family: "times new roman" , serif;">2 – 0</span></td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="534"><span style="font-family: "times new roman" , serif;">UNK/SBZP</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="48"><span style="font-family: "times new roman" , serif;">N</span></td></tr>
</tbody></table>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中<span style="font-family: "times new roman" , serif;">N[2:0] </span>用以表示<span style="font-family: "times new roman" , serif;">TTBR0</span>的寬度<span style="font-family: "times new roman" , serif;">,</span>也就是說<span style="font-family: "times new roman" , serif;">TTBR0</span>的<span style="font-family: "times new roman" , serif;">Base Address Bits</span>數為<span style="font-family: "times new roman" , serif;">[31:14-N],</span>如果<span style="font-family: "times new roman" , serif;">N=0,</span>表示<span style="font-family: "times new roman" , serif;">TTBR0</span>對應的<span style="font-family: "times new roman" , serif;">Table</span>大小為<span style="font-family: "times new roman" , serif;">14bits=16kbytes,</span>如果<span style="font-family: "times new roman" , serif;">N=b111=7,</span>表示<span style="font-family: "times new roman" , serif;">TTBT0</span>對應的<span style="font-family: "times new roman" , serif;">Table</span>大小為<span style="font-family: "times new roman" , serif;">7bits=128bytes.</span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: x-small;">可透過如下指令存取</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MRC p15,0,<Rt>,c2,c0,0 ; Read CP15 Translation Table Base Register 0</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MCR p15,0,<Rt>,c2,c0,0 ; Write CP15 Translation Table Base Register 0</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MRC p15,0,<Rt>,c2,c0,1 ; Read CP15 Translation Table Base Register 1</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MCR p15,0,<Rt>,c2,c0,1 ; Write CP15 Translation Table Base Register 1</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MRC p15,0,<Rt>,c2,c0,2 ; Read CP15 Translation Table Base Control Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">MCR p15,0,<Rt>,c2,c0,2 ; Write CP15 Translation Table Base Control Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>有關<span style="font-family: "times new roman" , serif;">Domain</span>控制參數<span style="font-family: "times new roman" , serif;">,,</span>可以透過<span style="font-family: "times new roman" , serif;">CP15</span>的暫存器<span style="font-family: "times new roman" , serif;">c3 </span>並取得 <span style="font-family: "times new roman" , serif;">Domain Access Control Register 32-bits</span>的值<span style="font-family: "times new roman" , serif;">.DACR</span>暫存器只能在特權等級下被存取<span style="font-family: "times new roman" , serif;">,</span>該暫存器如下圖所示會以各<span style="font-family: "times new roman" , serif;">2 bits</span>被區分為<span style="font-family: "times new roman" , serif;">16</span>個欄位<span style="font-family: "times new roman" , serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 807px;"><colgroup><col width="14"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="18"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>31</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>30</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>29</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>28</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>27</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>26</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>25</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>24</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>23</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>22</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>21</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>20</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>19</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>18</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>17</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>16</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>15</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>14</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>13</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>12</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>11</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>10</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>9</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>8</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>7</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>6</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>5</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>4</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>3</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>2</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="18"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></td></tr>
<tr class="alt" valign="TOP"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="39"><span style="font-family: "times new roman" , serif;">D15</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D14</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D13</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D12</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D11</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D10</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D9</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D8</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D7</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D6</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D5</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D4</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D3</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D2</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "times new roman" , serif;">D1</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="43"><span style="font-family: "times new roman" , serif;">D0</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>每個欄位各<span style="font-family: "times new roman" , serif;">2bits</span>的屬性意義如下所示<span style="font-family: "times new roman" , serif;"><br />(</span>參考這個連結 <span style="font-family: "times new roman" , serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0434b/CIHBCBFE.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0434b/CIHBCBFE.html</a></span></span><span style="color: navy;"><span style="text-decoration-line: underline;">)</span></span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 807px;"><colgroup><col width="186"></col><col width="599"></col></colgroup><tbody>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="186"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
欄位值</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="599"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="186"><span style="font-family: "times new roman" , serif;">b00</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="599"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">No access. Any access generates a domain fault.</span><span style="font-size: xx-small;"></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="186"><span style="font-family: "times new roman" , serif;">b01</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="599"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Client Mode. </span></span><span style="font-size: xx-small;">會對每個存取對應</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">TLB</span></span><span style="font-size: xx-small;">記憶體分頁的動作</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">執行</span><span style="font-size: xx-small;"> </span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Access Permission </span></span><span style="font-size: xx-small;">的檢查</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">.</span></span><span style="font-size: xx-small;">若有違反權限的存取行為</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">就會觸發 </span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">P</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">ermission Fault.</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="186"><span style="font-family: "times new roman" , serif;">b10</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="599"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Reserved. Any access generates a domain fault.</span><span style="font-size: xx-small;"></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="186"><span style="font-family: "times new roman" , serif;">b11</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="599"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Manager Mode. </span></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">將部會對存取記憶體分頁的動作進行</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Access Permission</span></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">的檢查</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">就算該記憶體設定為</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Read-Only</span></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">或是</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">eXecute Never(XN),</span></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">去寫入或是執行</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">,</span></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">都不會</span></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">觸發 </span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Permission Fault.</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-family: , "times new roman" , serif;"><span style="font-size: x-small;"></span></span></span><span style="font-family: , "times new roman" , serif;"><span style="font-size: x-small;">可透過如下指令存取</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: , "times new roman" , serif;"><span style="font-size: x-small;">MRC p15,0,<Rt>,c3,c0,0 ; Read CP15 Domain Access Control Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: , "times new roman" , serif;"><span style="font-size: x-small;">MCR p15,0,<Rt>,c3,c0,0 ; Write CP15 Domain Access Control Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: , "times new roman" , serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">有關處理器切換的</span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">Task ID</span></span><span style="font-size: x-small;">設置</span><span style="font-family: "times new roman" , serif;">,,</span>可以透過<span style="font-family: "times new roman" , serif;">CP15</span>的暫存器<span style="font-family: "times new roman" , serif;">c13 </span>取得 <span style="font-family: "times new roman" , serif;">Context ID Register (CONTEXTIDR) 32-bits</span>的值<span style="font-family: "times new roman" , serif;">. CONTEXTIDR</span>對應欄位意義如下所示</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 806px;"><colgroup><col width="591"></col><col width="193"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="591"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">31 — 8</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="193"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">7 — 0</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="591"><span style="font-family: , "times new roman" , serif;"><span style="font-size: x-small;">PROCID</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="193"><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">ASID</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>欄位說明如下所示</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 806px;"><colgroup><col width="197"></col><col width="587"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="197"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
欄位名稱</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="587"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="197"><span style="font-family: , "times new roman" , serif;"><span style="font-size: x-small;">PROCID</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="587">用以儲存每個處理器正在執行的<span style="font-family: "times new roman" , serif;">Task</span>唯一的識別碼<span style="font-family: "times new roman" , serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="197"><span style="font-family: "times new roman" , serif;">ASIC</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="587"><span style="font-family: "times new roman" , serif;">Application Space IDentifier</span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Address Space Identifier </span>用以記錄目前使用的記憶體空間識別碼<span style="font-family: "times new roman" , serif;">.</span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>可透過如下指令存取</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MRC p15,0,<Rt>,c13,c0,1 ; Read CP15 Context ID Register</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MCR p15,0,<Rt>,c13,c0,1 ; Write CP15 Context ID Register</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>除了<span style="font-family: "times new roman" , serif;">Task ID</span>本身<span style="font-family: "times new roman" , serif;">,CP15</span>的<span style="font-family: "times new roman" , serif;">c13</span>還提供<span style="font-family: "times new roman" , serif;">TPIDRURW (User Read/Write Thread ID Register),</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">TPIDRURO(User Read-only Thread ID Register),TPIDRPRW(Privileged Only Thread ID Register)</span>分別提供在<span style="font-family: "times new roman" , serif;">User-Mode/Kernel Mode Read/Write,User-Mode Read-Only Kernel Mode Read/Write</span>或只有<span style="font-family: "times new roman" , serif;">Kernel Mode</span>可以 <span style="font-family: "times new roman" , serif;">Read/Write</span>用以設定<span style="font-family: "times new roman" , serif;">Thread Id</span>的對應暫存器值<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>可透過如下指令存取</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MRC p15, 0, <Rt>, c13, c0, 2 ; Read CP15 User Read/Write Thread ID Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MCR p15, 0, <Rt>, c13, c0, 2 ; Write CP15 User Read/Write Thread ID Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MRC p15, 0, <Rt>, c13, c0, 3 ; Read CP15 User Read-only Thread ID Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MCR p15, 0, <Rt>, c13, c0, 3 ; Write CP15 User Read-only Thread ID Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MRC p15, 0, <Rt>, c13, c0, 4 ; Read CP15 Privileged Only Thread ID Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">MCR p15, 0, <Rt>, c13, c0, 4 ; Write CP15 Privileged Only Thread ID Register</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>接下來<span style="font-family: "times new roman" , serif;">,</span>說明一個<span style="font-family: "times new roman" , serif;">32bits</span>虛擬記憶體是如何透過<span style="font-family: "times new roman" , serif;">TLB</span>對應到實體記憶體的位址<span style="font-family: "times new roman" , serif;">,</span>如下表所示<span style="font-family: "times new roman" , serif;">,</span>可以區分為三個部分<span style="font-family: "times new roman" , serif;">,</span>分別為<span style="font-family: "times new roman" , serif;">12bits</span>的第一級<span style="font-family: "times new roman" , serif;">Table Index,10bits</span>的第二級<span style="font-family: "times new roman" , serif;">Table Index</span>與最後<span style="font-family: "times new roman" , serif;">10bits</span>的<span style="font-family: "times new roman" , serif;">Page Index,</span>以此細分最多可以把每個<span style="font-family: "times new roman" , serif;">Page</span>的大小細分到 <span style="font-family: "times new roman" , serif;">1Kbytes,</span>並對應到完整的<span style="font-family: "times new roman" , serif;">4GB</span>虛擬記憶體空間<span style="font-family: "times new roman" , serif;">. (2^12 * 2^10 * 1kbytes = 4GB.)</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 808px;"><colgroup><col width="280"></col><col width="261"></col><col width="235"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280"><span style="font-family: "times new roman" , serif;">31 — 20 (12-bits)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="261"><span style="font-family: "times new roman" , serif;">19 – 10 (10 bits)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="235"><span style="font-family: "times new roman" , serif;">9 – 0 (10bits)</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="280"><span style="font-family: "times new roman" , serif;">1<sup>st</sup> Table Index</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="261"><span style="font-family: "times new roman" , serif;">2<sup>nd</sup> Table Index</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="235"><span style="font-family: "times new roman" , serif;">Page Index</span></td></tr>
</tbody></table>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
第一級<span style="font-family: "times new roman" , serif;">Table</span>的描述內容如下所示</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilSJyOK_c7q5cASU_SOxrSGRJxcqT1RooryU-34X_OByPFUWv9JKi-giOtlahsQN_4yIkCv-5WVZTsSbMXWFT_pQMkyWfcZzzaWlNdWfeZ7cjd99sEosG_791yWvlkS7jSge_uKr0lia8/s1600/Table1%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="527" data-original-width="978" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilSJyOK_c7q5cASU_SOxrSGRJxcqT1RooryU-34X_OByPFUWv9JKi-giOtlahsQN_4yIkCv-5WVZTsSbMXWFT_pQMkyWfcZzzaWlNdWfeZ7cjd99sEosG_791yWvlkS7jSge_uKr0lia8/s1600/Table1%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">第二級</span><span style="font-family: "times new roman" , serif; font-size: 12.8px;">Table</span><span style="font-size: 12.8px;">的描述內容如下所示</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGsG8IxphXtx_G0ExazH8ZdGBBaJE4Bmqp0zFcYBY-YxoXdO5MEw3XQbnaGEplcuXIXxSvhh6cnoRsMCwtlzSrxkkurelvDEIM1s-l8YAsJ2HD9S7vbv1Ma5XZN1N7MPs3xvo6Z4uQokw/s1600/Table2%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="361" data-original-width="980" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGsG8IxphXtx_G0ExazH8ZdGBBaJE4Bmqp0zFcYBY-YxoXdO5MEw3XQbnaGEplcuXIXxSvhh6cnoRsMCwtlzSrxkkurelvDEIM1s-l8YAsJ2HD9S7vbv1Ma5XZN1N7MPs3xvo6Z4uQokw/s1600/Table2%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考 <span style="font-family: "times new roman" , serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0211h/Babifihd.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0211h/Babifihd.html</a></span></span> , </span>有關<span style="font-family: "times new roman" , serif;">Outer</span>與<span style="font-family: "times new roman" , serif;">Inner Cache</span>在有<span style="font-family: "times new roman" , serif;">L1</span>跟<span style="font-family: "times new roman" , serif;">L2 Cache</span>下的定義為 <span style="font-family: "times new roman" , serif;">Inner Cache</span>指的就是 <span style="font-family: "times new roman" , serif;">L1 Cache,</span>而<span style="font-family: "times new roman" , serif;">Outer Cache</span>指的就是<span style="font-family: "times new roman" , serif;">L2 Cache,</span>而在記憶體分頁的設定中<span style="font-family: "times new roman" , serif;">,</span>就可以根據<span style="font-family: "times new roman" , serif;">L1</span>或<span style="font-family: "times new roman" , serif;">L2 Cache</span>的相關行為<span style="font-family: "times new roman" , serif;">,</span>決定是否 <span style="font-family: "times new roman" , serif;">Cacheable ,Write-Through,Write-Back</span>或是<span style="font-family: "times new roman" , serif;">Write-Allocate. </span>一般而言<span style="font-family: "times new roman" , serif;">,L1</span>跟<span style="font-family: "times new roman" , serif;">L2</span>的<span style="font-family: "times new roman" , serif;">Cacheable</span>與<span style="font-family: "times new roman" , serif;">Bufferable</span>行為都會設定成一致<span style="font-family: "times new roman" , serif;">,</span>但搭配 <span style="font-family: "times new roman" , serif;">TEX,C</span>與<span style="font-family: "times new roman" , serif;">B</span>欄位<span style="font-family: "times new roman" , serif;">,</span>也可以根據系統實際的狀況<span style="font-family: "times new roman" , serif;">,</span>讓<span style="font-family: "times new roman" , serif;">L1</span>跟<span style="font-family: "times new roman" , serif;">L2 Cahce</span>可以依據系統所需的行為<span style="font-family: "times new roman" , serif;">,</span>而作差異化的調整<span style="font-family: "times new roman" , serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對應欄位的意義說明如下<span style="font-family: "times new roman" , serif;">,</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 807px;"><colgroup><col width="136"></col><col width="649"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
欄位名稱</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">C</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649"><span style="font-family: "times new roman" , serif;">Cacheable</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">B</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649"><span style="font-family: "times new roman" , serif;">Bufferable</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">TEX[2:0]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649"><span style="font-family: "times new roman" , serif;">TEX</span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">Type Extension (TEX) bit</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下以<span style="font-family: "times new roman" , serif;">SCTLR.TRE=0 (</span>透過<span style="font-family: "times new roman" , serif;">CP15</span>的<span style="font-family: "times new roman" , serif;">c1</span>取得 <span style="font-family: "times new roman" , serif;">System Control Register 32bits</span>值的<span style="font-family: "times new roman" , serif;">bit 28 </span>來設定<span style="font-family: "times new roman" , serif;">),</span>也就是<span style="font-family: "times new roman" , serif;">TEX Remap disabled</span>模式<span style="font-family: "times new roman" , serif;">,</span>來說明記憶體區段屬性的配置與意義<span style="font-family: "times new roman" , serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 651px;"><colgroup><col width="33"></col><col width="35"></col><col width="32"></col><col width="13"></col><col width="13"></col><col width="17"></col><col width="292"></col><col width="68"></col><col width="57"></col></colgroup><tbody>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">TEX[2]</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">TEX[1]</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">TEX[0]</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">C</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">B</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">S</span></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: xx-small;">說明</span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Memory Type</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Page Shareable</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">X</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Strongly-ordered</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Strongly-ordered</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Shareable</span></span></td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">X</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Shareable Device</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Device</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Shareable</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">O</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Outer and Inner Write-Through, no</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Write-Allocate</span></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Normal</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Depond on S bit</span></span></td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">O</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Outer and Inner Write-Back, no Write-Allocate</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Normal</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Depond on S bit</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">O</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Outer and Inner Non-cacheable</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Normal</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Depond on S bit</span></span></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">X</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Reserved</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">X</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">IMPLEMENTATION DEFINED</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">IMPLEMENTATION DEFINED</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">IMPLEMENTATION DEFINED</span></span></td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">O</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Outer and Inner Write-Back, Write-Allocate</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Normal</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Depond on S bit</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Non-shareable Device</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Device</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Non-shareable</span></span></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Reserved</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">X</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Reserved</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">X</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">X</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Reserved</span></span></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"></td><td bgcolor="#b3b3b3" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"></td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="color: red;"><span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>B</strong></span></span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="32"><span style="color: red;"><span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>B</strong></span></span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: red;"><span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>A</strong></span></span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: red;"><span style="font-family: "times new roman" , serif;"><span style="font-size: small;"><strong>A</strong></span></span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">O</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="292"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">AA </span></span><span style="font-size: xx-small;">用來設定</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Inner Cache(L1 Cache</span></span><span style="font-size: xx-small;">的參數</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">)</span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">BB </span></span><span style="font-size: xx-small;">用來設定</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Outer Cachel(L2 Cache</span></span><span style="font-size: xx-small;">的參數</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">)</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 296px;"><colgroup><col width="117"></col><col width="157"></col></colgroup><tbody>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">AA</span></span><span style="font-size: xx-small;">或</span><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">BB</span></span><span style="font-size: xx-small;">的編碼值</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: xx-small;">說明</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "times new roman" , serif;">0 0</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Non-cacheable</span></span></td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "times new roman" , serif;">0 1</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Write-Back, Write-Allocate</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "times new roman" , serif;">1 0</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Write-Through, no Write-Allocate</span></span></td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "times new roman" , serif;">1 1</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Write-Back, no Write-Allocate</span></span></td></tr>
</tbody></table>
</td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="68"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Normal</span></span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;"><span style="font-size: xx-small;">Depond on S bit</span></span></td></tr>
</tbody></table>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">XN</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649">為<span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>Execute Never </strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>的屬性</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>,</strong></span></span></span>若該記憶體分頁 <span style="font-family: "times new roman" , serif;">XN Bit</span>設定為<span style="font-family: "times new roman" , serif;">1,</span>表示該分頁不會被處理器<span style="font-family: "times new roman" , serif;">Fetch</span>指令進來執行<span style="font-family: "times new roman" , serif;">,</span>在<span style="font-family: "times new roman" , serif;">Client Domain (</span>也就是會稽核 <span style="font-family: "times new roman" , serif;">Access Permission</span>狀態<span style="font-family: "times new roman" , serif;">)</span>下<span style="font-family: "times new roman" , serif;">,</span>記憶體分頁必須要 <span style="font-family: "times new roman" , serif;">XN Bit</span>為<span style="font-family: "times new roman" , serif;">0,</span>且記憶體屬性是設定為可讀取<span style="font-family: "times new roman" , serif;">,</span>同時沒有其他<span style="font-family: "times new roman" , serif;">Prefech Abort</span>發生的狀態下<span style="font-family: "times new roman" , serif;">,</span>才可以被執行<span style="font-family: "times new roman" , serif;">. </span>如果該記憶體分頁是屬於<span style="font-family: "times new roman" , serif;">Manager Domain,XN Bit</span>就不會被當做稽核的條件<span style="font-family: "times new roman" , serif;">. (</span>所以就可以嘗試去執行<span style="font-family: "times new roman" , serif;">,</span>而不會導致例外發生<span style="font-family: "times new roman" , serif;">).</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">NS</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649">這個屬性在支援 <span style="font-family: "times new roman" , serif;">Trust Zone Security Extensions</span>環境下<span style="font-family: "times new roman" , serif;">,</span>才會有作用<span style="font-family: "times new roman" , serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">Domain</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649">參考<span style="font-family: "times new roman" , serif;">ARMv7</span>的文件<span style="font-family: "times new roman" , serif;">, VMSA() </span>會以<span style="font-family: "times new roman" , serif;">4-bits</span>表示<span style="font-family: "times new roman" , serif;">Domain</span>的<span style="font-family: "times new roman" , serif;">Index,</span>也就是說最大可以定義到<span style="font-family: "times new roman" , serif;">16</span>個<span style="font-family: "times new roman" , serif;">Domain,</span>每個<span style="font-family: "times new roman" , serif;">Domain Index</span>會依序對應到<span style="font-family: "times new roman" , serif;">Domain Access Control Register 32-bits</span>值中以各<span style="font-family: "times new roman" , serif;">2-bits</span>依序產生的<span style="font-family: "times new roman" , serif;">16</span>個欄位<span style="font-family: "times new roman" , serif;">.</span></td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: , serif;"><span style="font-size: xx-small;"><strong>AP[2], AP[1:0]</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649"><table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 651px;"><colgroup><col width="57"></col><col width="61"></col><col width="67"></col><col width="128"></col><col width="130"></col><col width="148"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">AP[2]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">AP[1]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">AP[0]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>Privileged</strong></span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>permissions</strong></span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>User</strong></span></span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>permissions</strong></span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "times new roman" , serif;">No Access</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"><span style="font-family: "times new roman" , serif;">No Access</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">All accesses generate Permission faults</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "times new roman" , serif;">Read/Write</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"><span style="font-family: "times new roman" , serif;">No Access</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Privileged access only</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "times new roman" , serif;">Read/Write</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"><span style="font-family: "times new roman" , serif;">Read Only</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Writes in User mode generate Permission faults</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "times new roman" , serif;">Read/Write</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"><span style="font-family: "times new roman" , serif;">Read/Write</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Full access</span></span></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">1</span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">0</span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">0</span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Reserved</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "times new roman" , serif;">Read Only</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"><span style="font-family: "times new roman" , serif;">No Access</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Privileged read-only</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "times new roman" , serif;">Read Only</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"><span style="font-family: "times new roman" , serif;">Read Only</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Privileged and User read-only, deprecated in VMSAv7</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="57"><span style="font-family: "times new roman" , serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "times new roman" , serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="67"><span style="font-family: "times new roman" , serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "times new roman" , serif;">Read Only</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="130"><span style="font-family: "times new roman" , serif;">Read Only</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;">Privileged and User read-only</span></span></td></tr>
</tbody></table>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">S</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649">用以定義該記憶體分頁是否為<span style="font-family: "times new roman" , serif;">Shareable,S</span>為 <span style="font-family: "times new roman" , serif;">0 </span>表示該記憶體分頁為<span style="font-family: "times new roman" , serif;">Non-shareable,S </span>為 <span style="font-family: "times new roman" , serif;">1 </span>表示該記憶體分頁為 <span style="font-family: "times new roman" , serif;">Shareable.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">nG</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649">這屬性為<span style="font-family: "times new roman" , serif;">N<span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>on-Global,</strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>用來定義該記憶體分頁是否為</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>Global,</strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>如果</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>nG</strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>為</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>0,</strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>表示該記憶體分頁為</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>Global,</strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>如果為</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>1,</strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>表示該記憶體分頁屬於目前正在運作的</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>ASID(Address Space Identifier),</strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>該值會對應到正在運作的</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>Task (</strong></span></span></span><span style="font-family: , sans-serif;"><span style="font-size: xx-small;"><strong>請參考</strong></span></span><span style="font-family: "times new roman" , serif;"><span style="font-family: , "times new roman" , serif;"><span style="font-size: xx-small;"><strong>CONTEXTIDR)</strong></span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "times new roman" , serif;">Bit [18]</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649"><span style="font-family: "times new roman" , serif;">when bits [1:0] == 0b10</span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">0 Descriptor is for a Section</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;">1 Descriptor is for a Supersection.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="649"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>有關<span style="font-family: "times new roman" , serif;">3bits AP (Access Permission)</span>與<span style="font-family: "times new roman" , serif;">4bits Domain</span>對應的行為<span style="font-family: "times new roman" , serif;">,</span>說明如下所示</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 804px;"><colgroup><col width="149"></col><col width="632"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="149"><span style="font-family: "times new roman" , serif;">Manager Domain</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="632">若 <span style="font-family: "times new roman" , serif;">Domain=1,</span>且參考<span style="font-family: "times new roman" , serif;">Domain Access Control Register</span>對應到<span style="font-family: "times new roman" , serif;">Domain Field 1</span>的值為<span style="font-family: "times new roman" , serif;">0b11,</span>也就是<span style="font-family: "times new roman" , serif;">Manage Domain,</span>此時如果<span style="font-family: "times new roman" , serif;">,AP[2:0]</span>值為<span style="font-family: "times new roman" , serif;">0b000,</span>也就是<span style="font-family: "times new roman" , serif;">Privileged/User Mode</span>都是 <span style="font-family: "times new roman" , serif;">No Access,</span>由於此時為<span style="font-family: "times new roman" , serif;">Manager Domain,</span>因此對任何記憶體範圍的存取都不會進行權限的檢查動作<span style="font-family: "times new roman" , serif;">,</span>因此不管此時是處於<span style="font-family: "times new roman" , serif;">Privileged/User Mode,</span>都可以對該記憶體內容進行存取的動作<span style="font-family: "times new roman" , serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="149"><span style="font-family: "times new roman" , serif;">Client Domain</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="632">若 <span style="font-family: "times new roman" , serif;">Domain=2,</span>且參考<span style="font-family: "times new roman" , serif;">Domain Access Control Register</span>對應到<span style="font-family: "times new roman" , serif;">Domain Field 2</span>的值為<span style="font-family: "times new roman" , serif;">0b01,</span>也就是<span style="font-family: "times new roman" , serif;">Client Domain,</span>此時如果<span style="font-family: "times new roman" , serif;">,AP[2:0]</span>值為<span style="font-family: "times new roman" , serif;">0b010,</span>也就是<span style="font-family: "times new roman" , serif;">Privileged Mode</span>為 <span style="font-family: "times new roman" , serif;">Read/Write,User Mode</span>為<span style="font-family: "times new roman" , serif;">Read Only.</span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果此時<span style="font-family: "times new roman" , serif;">CPU</span>處於<span style="font-family: "times new roman" , serif;">Privileged Mode,</span>可以對該記憶體進行讀寫</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若此時<span style="font-family: "times new roman" , serif;">CPU</span>處於<span style="font-family: "times new roman" , serif;">User Mode,</span>則只允許對該記憶體進行讀取<span style="font-family: "times new roman" , serif;">,</span>寫入的動作會導致<span style="font-family: "times new roman" , serif;">Permission faults</span></div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="149"><span style="font-family: "times new roman" , serif;">Client Domain</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="632">若 <span style="font-family: "times new roman" , serif;">Domain=3,</span>且參考<span style="font-family: "times new roman" , serif;">Domain Access Control Register</span>對應到<span style="font-family: "times new roman" , serif;">Domain Field 3</span>的值為<span style="font-family: "times new roman" , serif;">0b01,</span>也就是<span style="font-family: "times new roman" , serif;">Client Domain,</span>此時如果<span style="font-family: "times new roman" , serif;">,AP[2:0]</span>值為<span style="font-family: "times new roman" , serif;">0b001,</span>也就是<span style="font-family: "times new roman" , serif;">Privileged Mode</span>為 <span style="font-family: "times new roman" , serif;">Read/Write,User Mode</span>為<span style="font-family: "times new roman" , serif;">No Access.</span><br />
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果此時<span style="font-family: "times new roman" , serif;">CPU</span>處於<span style="font-family: "times new roman" , serif;">Privileged Mode,</span>可以對該記憶體進行讀寫</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若此時<span style="font-family: "times new roman" , serif;">CPU</span>處於<span style="font-family: "times new roman" , serif;">User Mode,</span>對該記憶體的存取動作<span style="font-family: "times new roman" , serif;">,</span>都會導致<span style="font-family: "times new roman" , serif;">Permission faults</span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>根據<span style="font-family: "times new roman" , serif;">TLB</span>的設定參數組合<span style="font-family: "times new roman" , serif;">,</span>接下來分別以基於<span style="font-family: "times new roman" , serif;">16MB(SuperSection),1MB(Section),64KB(Large Page),4KB(Small Page)</span>與<span style="font-family: "times new roman" , serif;">1KB(Tiny Page)</span>不同分頁的組合<span style="font-family: "times new roman" , serif;">,</span>來說明<span style="font-family: "times new roman" , serif;">TLB 1</span>級與<span style="font-family: "times new roman" , serif;">2</span>級 <span style="font-family: "times new roman" , serif;">Table</span>的運作概念<span style="font-family: "times new roman" , serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "times new roman" , serif;"></span>如下所示為<span style="font-family: "times new roman" , serif;">16MB(SuperSection) </span>配置下<span style="font-family: "times new roman" , serif;">,TLB</span>分頁運作的概念</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHPXnijHHQJIFW0yVeWKbixVepBWCD0kSvPK4q1DrRIVqqbU_Ep8x-iz7cHFbuLYirGIBQ6A3AIl3_Jqg2_bOOjMtFEWccQ_lhwP3O-GYSxWoPKrqcHUP6DzFcfvsBo69hhk-ZQYahyJg/s1600/image008%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="542" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHPXnijHHQJIFW0yVeWKbixVepBWCD0kSvPK4q1DrRIVqqbU_Ep8x-iz7cHFbuLYirGIBQ6A3AIl3_Jqg2_bOOjMtFEWccQ_lhwP3O-GYSxWoPKrqcHUP6DzFcfvsBo69hhk-ZQYahyJg/s1600/image008%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;">如下所示為</span><span style="font-family: "times new roman" , serif; font-size: 12.8px;">1MB(Section) </span><span style="font-size: 12.8px;">配置下</span><span style="font-family: "times new roman" , serif; font-size: 12.8px;">,TLB</span><span style="font-size: 12.8px;">分頁運作的概念</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhP3x-Wpb4MB0n-jqZyjScC84jpTR_iU77MixhBx9BzPjwQ12h0OYWPRyYkKdHXNdiZqIiOVs4o5ou1XXRbk1a3Iatfv6j1WH_hrO7p2rLK3-2nM2capdy8CrmV3HyfWbMDwQtsibECIZk/s1600/image010%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="548" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhP3x-Wpb4MB0n-jqZyjScC84jpTR_iU77MixhBx9BzPjwQ12h0OYWPRyYkKdHXNdiZqIiOVs4o5ou1XXRbk1a3Iatfv6j1WH_hrO7p2rLK3-2nM2capdy8CrmV3HyfWbMDwQtsibECIZk/s1600/image010%255B1%255D.png" /></a></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;">如下所示為</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">64KB(Large Page) </span><span style="font-size: 12.8px;">配置下</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">,TLB</span><span style="font-size: 12.8px;">分頁運作的概念</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3sRpDYlLXjszeyvOwvmOB6wz2_DVe55H5dnhLauD8smOdVvc7o1Y30AOz3kt_Pv1dHIP-_nWZ2mGzD_oi4qtEjdlqCwowj_M4J0a2ikzyrbOjCZP-AhkNQQpveaBXnIgh4LhGPQtS_1Q/s1600/image012%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="614" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3sRpDYlLXjszeyvOwvmOB6wz2_DVe55H5dnhLauD8smOdVvc7o1Y30AOz3kt_Pv1dHIP-_nWZ2mGzD_oi4qtEjdlqCwowj_M4J0a2ikzyrbOjCZP-AhkNQQpveaBXnIgh4LhGPQtS_1Q/s1600/image012%255B1%255D.png" /></a></div>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;">如下所示為</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">4KB(Small Page) </span><span style="font-size: 12.8px;">配置下</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">,TLB</span><span style="font-size: 12.8px;">分頁運作的概念</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKN3CEQfkGsKCDYq70s65I-0gCoiIWImuKBxUHOq2qC_dxEmkzBPUorO8eHw1N57b99pru-SVGRayv-wPmTiIivZv6p2GhJnVVhZ1R3-QZaB2TMqSsSWKzLuo-1cdDnJMLuePpfLsTXgw/s1600/image014%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="614" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKN3CEQfkGsKCDYq70s65I-0gCoiIWImuKBxUHOq2qC_dxEmkzBPUorO8eHw1N57b99pru-SVGRayv-wPmTiIivZv6p2GhJnVVhZ1R3-QZaB2TMqSsSWKzLuo-1cdDnJMLuePpfLsTXgw/s1600/image014%255B1%255D.png" /></a></div>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;">如下所示為</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">1KB(Tiny Page) </span><span style="font-size: 12.8px;">配置下</span><span style="font-family: "Times New Roman", serif; font-size: 12.8px;">,TLB</span><span style="font-size: 12.8px;">分頁運作的概念</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuRGYVWxGTQNi7A_5BaQVzEbdp9mEBTeRpzGFlLmDF5C46HbSk7M4TTpZ99by5Bkn5fn9ZE3TOjPzqkSBr5DN8qw7fjvcgbBZoP7rtXLy9etCQKOplbR5NAlS0mA6_2YeRpS3WdVDsF2w/s1600/image016%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="613" data-original-width="803" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuRGYVWxGTQNi7A_5BaQVzEbdp9mEBTeRpzGFlLmDF5C46HbSk7M4TTpZ99by5Bkn5fn9ZE3TOjPzqkSBr5DN8qw7fjvcgbBZoP7rtXLy9etCQKOplbR5NAlS0mA6_2YeRpS3WdVDsF2w/s1600/image016%255B1%255D.png" /></a></div>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Fast Context-Switch Extension (FCSE)</strong></span></span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<span style="font-size: 12.8px;"></span><br />
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>快速行程切換主要支援以<span style="font-family: "Times New Roman", serif;">32MB</span>記憶體範圍為單位<span style="font-family: "Times New Roman", serif;">,</span>把<span style="font-family: "Times New Roman", serif;">Virtual Address</span>轉為<span style="font-family: "Times New Roman", serif;">Modified Virtual Address</span>對應的空間<span style="font-family: "Times New Roman", serif;">,</span>如下圖所示<span style="font-family: "Times New Roman", serif;">,</span>虛擬記憶體位址會透過<span style="font-family: "Times New Roman", serif;">FCSE</span>邏輯<span style="font-family: "Times New Roman", serif;">,</span>轉為修正後的虛擬記憶體位址<span style="font-family: "Times New Roman", serif;">,</span>再透過<span style="font-family: "Times New Roman", serif;">MMU</span>對應到實體記憶體空間<span style="font-family: "Times New Roman", serif;">(Physical Memory Address),</span>也就是說<span style="font-family: "Times New Roman", serif;">,</span>基於<span style="font-family: "Times New Roman", serif;">FCSE</span>整個系統可以共用同一份虛擬記憶體空間配置表<span style="font-family: "Times New Roman", serif;">,</span>不需要在每個<span style="font-family: "Times New Roman", serif;">Task</span>切換時<span style="font-family: "Times New Roman", serif;">,</span>更新整個虛擬記憶體空間配置表<span style="font-family: "Times New Roman", serif;">,</span>只需要把各自對應的<span style="font-family: "Times New Roman", serif;">32MB</span>起點位置透過<span style="font-family: "Times New Roman", serif;">FCSE</span>對應到目前所在虛擬記憶體空間的對應位置<span style="font-family: "Times New Roman", serif;">(Modified Virtual Memory Address)</span>即可<span style="font-family: "Times New Roman", serif;">.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ-acMXfc3tbSpCsZKhQeOy5zqIrLcY5gsYszBTD6psf8n2Eub8154kjM-Mhb_3Ti7fkLER35a5jtLkiwfCHAXS6qw-rdt8ge8xpczJ5hD2KoL8LOR_7ww4Gq6A5t7qzAmTaKUH8zTJn4/s1600/image018%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="376" data-original-width="802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ-acMXfc3tbSpCsZKhQeOy5zqIrLcY5gsYszBTD6psf8n2Eub8154kjM-Mhb_3Ti7fkLER35a5jtLkiwfCHAXS6qw-rdt8ge8xpczJ5hD2KoL8LOR_7ww4Gq6A5t7qzAmTaKUH8zTJn4/s1600/image018%255B1%255D.png" /></a></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><br /></span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">FCSE</span>最多只能切割<span style="font-family: "Times New Roman", serif;">128</span>個<span style="font-family: "Times New Roman", serif;">32MB</span>記憶體空間<span style="font-family: "Times New Roman", serif;">,</span>並對應到<span style="font-family: "Times New Roman", serif;">4GB</span>的虛擬記憶體配置<span style="font-family: "Times New Roman", serif;">,</span>同時<span style="font-family: "Times New Roman", serif;">,</span>每個<span style="font-family: "Times New Roman", serif;">Task</span>各自擁有的虛擬記憶體空間必須是<span style="font-family: "Times New Roman", serif;">0x00000000</span>起點的記憶體位置<span style="font-family: "Times New Roman", serif;">,</span>並依據<span style="font-family: "Times New Roman", serif;">7bits</span>的<span style="font-family: "Times New Roman", serif;">PID</span>來對應到各自的<span style="font-family: "Times New Roman", serif;">32MB</span>記憶體區塊<span style="font-family: "Times New Roman", serif;">,</span>運作行為可用以下的簡式來說明</div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">if(VA[31:25] ==0) then</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MVA = VA | (PID<<25)</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">else</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MVA = VA</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>參考<span style="font-family: "Times New Roman", serif;">ARM1176JZ-S Technical Reference Manual,ARM</span>為了讓早期<span style="font-family: "Times New Roman", serif;">Windows CE </span>每個行程各自<span style="font-family: "Times New Roman", serif;">32MB</span>虛擬記憶體空間的設計<span style="font-family: "Times New Roman", serif;">,</span>可以有效的運作<span style="font-family: "Times New Roman", serif;">,</span>因此提供了快速行程切換<span style="font-family: "Times New Roman", serif;">(FCSE)</span>機制<span style="font-family: "Times New Roman", serif;">.</span>當發生<span style="font-family: "Times New Roman", serif;">Task</span>切換時<span style="font-family: "Times New Roman", serif;">,</span>可以透過設定<span style="font-family: "Times New Roman", serif;">CP15 c13 </span>暫存器中<span style="font-family: "Times New Roman", serif;">FCSE PID</span>的值<span style="font-family: "Times New Roman", serif;">,</span>決定<span style="font-family: "Times New Roman", serif;">FCSE</span>所要轉換的記憶體空間<span style="font-family: "Times New Roman", serif;">,</span>對應帶來的好處就是<span style="font-family: "Times New Roman", serif;">,</span>由於整個系統在<span style="font-family: "Times New Roman", serif;">Task</span>切換後<span style="font-family: "Times New Roman", serif;">,</span>還是基於同一份<span style="font-family: "Times New Roman", serif;">TLB</span>的虛擬記憶體配置表<span style="font-family: "Times New Roman", serif;">,</span>同時配置表中的內容仍舊是有效的<span style="font-family: "Times New Roman", serif;">,</span>只是透過<span style="font-family: "Times New Roman", serif;">FCSE</span>把運作的<span style="font-family: "Times New Roman", serif;">Task</span>虛擬<span style="font-family: "Times New Roman", serif;">32MB</span>記憶體空間轉換到對應的位置<span style="font-family: "Times New Roman", serif;">,</span>因此<span style="font-family: "Times New Roman", serif;">,</span>可以減少<span style="font-family: "Times New Roman", serif;">TLB Flush</span>的成本<span style="font-family: "Times New Roman", serif;">,</span>減少<span style="font-family: "Times New Roman", serif;">Task Context-Switch</span>切換的成本<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>可透過如下程式碼讀<span style="font-family: "Times New Roman", serif;">/</span>寫<span style="font-family: "Times New Roman", serif;">FCSE PID</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p15, 0, <Rd>, c13, c0, 0; Read FCSE PID Register</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p15, 0, <Rd>, c13, c0, 0; Write FCSE PID Register</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>暫存器格式如下所示</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="border-collapse: collapse; color: black; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="14"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="16"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">31</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">30</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">29</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">28</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">27</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">26</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">25</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">24</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">23</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">22</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">21</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">20</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">19</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">18</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">17</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">16</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">15</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">14</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">13</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">12</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">11</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">10</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">9</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">7</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">6</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">5</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">4</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">3</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="16"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></td></tr>
<tr valign="TOP"><td colspan="7" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="165"><span style="font-family: "Times New Roman", serif;">FCSE PID</span></td><td colspan="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="619"><span style="font-family: "Times New Roman", serif;">SBZ</span></td></tr>
</tbody></table>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>參考網頁<span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Windows_Embedded_CE_6.0" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/Windows_Embedded_CE_6.0</a></span></span> </span>的說明 <span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">Windows CE 6</span>以前<span style="font-family: "Times New Roman", serif;">,</span>每個應用程式只能擁有屬於各自<span style="font-family: "Times New Roman", serif;">32MB</span>的虛擬記憶體空間<span style="font-family: "Times New Roman", serif;">,</span>並且最多只能有<span style="font-family: "Times New Roman", serif;">32</span>個<span style="font-family: "Times New Roman", serif;">Tasks</span>被載入到記憶體中<span style="font-family: "Times New Roman", serif;">, </span>到了<span style="font-family: "Times New Roman", serif;">Windows CE 6</span>之後的核心<span style="font-family: "Times New Roman", serif;">,</span>選擇支援完整的記憶體分頁機制<span style="font-family: "Times New Roman", serif;">,</span>提供每個<span style="font-family: "Times New Roman", serif;">Task</span>各自<span style="font-family: "Times New Roman", serif;">2GB</span>的虛擬記憶體空間<span style="font-family: "Times New Roman", serif;">,</span>並支援最多<span style="font-family: "Times New Roman", serif;">32768 (2^15)</span>個<span style="font-family: "Times New Roman", serif;">Tasks</span>被載入到記憶體中<span style="font-family: "Times New Roman", serif;">. </span>對應到<span style="font-family: "Times New Roman", serif;">Windows Mobile</span>的版本<span style="font-family: "Times New Roman", serif;">,</span>則是直到<span style="font-family: "Times New Roman", serif;">Windows Phone 7 </span>才採用<span style="font-family: "Times New Roman", serif;">Windows CE 6.0 R3</span>的核心<span style="font-family: "Times New Roman", serif;">,</span>解除了每個應用程式<span style="font-family: "Times New Roman", serif;">32MB</span>虛擬記憶體的限制<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>在<span style="font-family: "Times New Roman", serif;">ARM11(ARMv6)</span>並不建議採用<span style="font-family: "Times New Roman", serif;">FCSE,</span>而在<span style="font-family: "Times New Roman", serif;">Cortex (ARMv7)</span>方案中<span style="font-family: "Times New Roman", serif;">,FCSE</span>為一個<span style="font-family: "Times New Roman", serif;">Optional</span>選項<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Micro TLB</strong></span></span><span style="font-size: small;"><strong>與</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Main TLB(Translation Lookaside Buffer)</strong></span></span><span style="font-size: small;"><strong>架構</strong></span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>參考相關<span style="font-family: "Times New Roman", serif;">Two-Level TLB (Micro/Main)</span>架構的文件<span style="font-family: "Times New Roman", serif;">,</span>為了要減少<span style="font-family: "Times New Roman", serif;">TLB</span>查詢對外部記憶體存取的成本<span style="font-family: "Times New Roman", serif;">,</span>因此在<span style="font-family: "Times New Roman", serif;">On-Chip</span>上增加<span style="font-family: "Times New Roman", serif;">SRAM,</span>透過高速的記憶體<span style="font-family: "Times New Roman", serif;">,Micro TLB</span>可以在<span style="font-family: "Times New Roman", serif;">1</span>個<span style="font-family: "Times New Roman", serif;">CPU Clock</span>就完成查詢的結果<span style="font-family: "Times New Roman", serif;">,</span>若<span style="font-family: "Times New Roman", serif;">Miss,</span>才是到<span style="font-family: "Times New Roman", serif;">Main TLB</span>查詢<span style="font-family: "Times New Roman", serif;">,</span>若還是<span style="font-family: "Times New Roman", serif;">Miss,</span>才是到外部記憶體上的<span style="font-family: "Times New Roman", serif;">TLB</span>查詢<span style="font-family: "Times New Roman", serif;">. </span>另外這篇論文 <span style="font-family: "Times New Roman", serif;">“An Advanced Filtering TLB for Low Power Consumption”(</span>參考網址<span style="font-family: "Times New Roman", serif;">:<span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://supercom.yonsei.ac.kr/paper/An%20advanced%20filtering%20TLB%20for%20low%20power%20consumption.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://supercom.yonsei.ac.kr/paper/An%20advanced%20filtering%20TLB%20for%20low%20power%20consumption.pdf</a></span></span> ),</span>以<span style="font-family: "Times New Roman", serif;">Strong ARM</span>為例<span style="font-family: "Times New Roman", serif;">(</span>記憶中時脈約為<span style="font-family: "Times New Roman", serif;">200MHz),</span>在功耗的消耗上<span style="font-family: "Times New Roman", serif;">,</span>個記憶體區塊大約各佔<span style="font-family: "Times New Roman", serif;">Instruction Cache:27%,TLB(Translation Lookaside Buffer ):17%</span>與<span style="font-family: "Times New Roman", serif;">Data Cache:16%,</span>由此可知<span style="font-family: "Times New Roman", serif;">Instruction Cache</span>與<span style="font-family: "Times New Roman", serif;">TLB</span>在處理器運作時<span style="font-family: "Times New Roman", serif;">,</span>是相當頻繁被存取使用的<span style="font-family: "Times New Roman", serif;">.</span>同時<span style="font-family: "Times New Roman", serif;">,</span>當<span style="font-family: "Times New Roman", serif;">Micro/Main TLB</span>支援筆數增加<span style="font-family: "Times New Roman", serif;">,</span>虛擬記憶體查詢<span style="font-family: "Times New Roman", serif;">Miss Rate</span>就會降低<span style="font-family: "Times New Roman", serif;">,</span>且對外部記憶體<span style="font-family: "Times New Roman", serif;">TLB</span>查詢的次數減少<span style="font-family: "Times New Roman", serif;">,</span>也可降低功耗<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">TLB</span>本身為一個<span style="font-family: "Times New Roman", serif;">On-Chip</span>的記憶體區塊<span style="font-family: "Times New Roman", serif;">,</span>當處理器要去查詢外部記憶體的記憶體分頁表格時<span style="font-family: "Times New Roman", serif;">,</span>如果要查詢的目的記憶體位址存在於<span style="font-family: "Times New Roman", serif;">TLB</span>暫存的記憶體中<span style="font-family: "Times New Roman", serif;">,</span>就會由<span style="font-family: "Times New Roman", serif;">TLB</span>直接返回<span style="font-family: "Times New Roman", serif;">,</span>反之如果該記憶體位置不在目前<span style="font-family: "Times New Roman", serif;">TLB</span>暫存的範圍中<span style="font-family: "Times New Roman", serif;">,</span>就會到外部記憶體分頁表格中查詢<span style="font-family: "Times New Roman", serif;">,</span>並且把查詢的結果記錄到<span style="font-family: "Times New Roman", serif;">TLB</span>中<span style="font-family: "Times New Roman", serif;">,</span>以便在下次又查詢同樣的記憶體位址時<span style="font-family: "Times New Roman", serif;">,</span>可以很快速的回應<span style="font-family: "Times New Roman", serif;">,</span>省去要到外部記憶體查詢的成本<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>當外部記憶體的記憶體分頁表格因為 <span style="font-family: "Times New Roman", serif;">Task Context-Switch</span>切換而變動時<span style="font-family: "Times New Roman", serif;">,</span>我們會透過<span style="font-family: "Times New Roman", serif;">CP15 c2</span>暫存器來修改<span style="font-family: "Times New Roman", serif;">TLB Base Address,</span>並且<span style="font-family: "Times New Roman", serif;">Flush TLB</span>快取暫存中的內容<span style="font-family: "Times New Roman", serif;">(</span>因為已經對應到新的<span style="font-family: "Times New Roman", serif;">Task</span>記憶體分頁內容<span style="font-family: "Times New Roman", serif;">),</span>相關<span style="font-family: "Times New Roman", serif;">Flush</span>的動作可以透過<span style="font-family: "Times New Roman", serif;">CP15 c8</span>暫存器來執行<span style="font-family: "Times New Roman", serif;">,</span>如果有些虛擬記憶體對應的內容並不希望因為<span style="font-family: "Times New Roman", serif;">Task Context-Switch</span>切換<span style="font-family: "Times New Roman", serif;">,</span>被<span style="font-family: "Times New Roman", serif;">TLB Flush</span>所清除<span style="font-family: "Times New Roman", serif;">,</span>則可以透過<span style="font-family: "Times New Roman", serif;">CP15 c10</span>暫存器<span style="font-family: "Times New Roman", serif;">,</span>進行<span style="font-family: "Times New Roman", serif;">TLB Lock-Down</span>的動作<span style="font-family: "Times New Roman", serif;">,</span>讓該記憶體對應位址的內容可以保存在<span style="font-family: "Times New Roman", serif;">TLB</span>暫存記憶體中<span style="font-family: "Times New Roman", serif;">,</span>進而加入相關記憶體轉換的速度<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>在<span style="font-family: "Times New Roman", serif;">Cortex A(ARMv7)</span>的<span style="font-family: "Times New Roman", serif;">Virtual Memory System Architecture </span>對記憶體管理部分有如下的演進<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>記憶體分頁包括<span style="font-family: "Times New Roman", serif;">4KB,64KB,1MB</span>與<span style="font-family: "Times New Roman", serif;">16MB.</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,</span>支援記憶體分頁<span style="font-family: "Times New Roman", serif;">16</span>個<span style="font-family: "Times New Roman", serif;">Domains</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>支援記憶體分頁<span style="font-family: "Times New Roman", serif;">Global</span>與<span style="font-family: "Times New Roman", serif;">ASID(Address space identifiers)</span>機制<span style="font-family: "Times New Roman", serif;">,</span>避免當<span style="font-family: "Times New Roman", serif;">Task Context-Switch</span>發生時<span style="font-family: "Times New Roman", serif;">,TLB</span>被<span style="font-family: "Times New Roman", serif;">Flush</span>的成本<span style="font-family: "Times New Roman", serif;">. (</span>屬於<span style="font-family: "Times New Roman", serif;">Global</span>的分頁是不屬於特定的<span style="font-family: "Times New Roman", serif;">Task,</span>且<span style="font-family: "Times New Roman", serif;">ASID 8-bits</span>可用來識別不同<span style="font-family: "Times New Roman", serif;">Task</span>記憶體配置的<span style="font-family: "Times New Roman", serif;">ID)</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,</span>延伸<span style="font-family: "Times New Roman", serif;">Access Permission</span>的能力<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>在<span style="font-family: "Times New Roman", serif;">Cortex A9</span>中<span style="font-family: "Times New Roman", serif;">,</span>為了支援多核心的架構<span style="font-family: "Times New Roman", serif;">,</span>記憶體管理機制做了以下的演進<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>支援<span style="font-family: "Times New Roman", serif;">32</span>筆項目的<span style="font-family: "Times New Roman", serif;">Instruction Micro TLB</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,</span>支援<span style="font-family: "Times New Roman", serif;">32</span>筆項目的<span style="font-family: "Times New Roman", serif;">Data Micro TLB</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>支援一致的<span style="font-family: "Times New Roman", serif;">Main TLB</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,</span>支援<span style="font-family: "Times New Roman", serif;">L1 Data Cache</span>的<span style="font-family: "Times New Roman", serif;">Page Table</span>查詢硬體<span style="font-family: "Times New Roman", serif;">. (</span>可以用來確保每個處理器<span style="font-family: "Times New Roman", serif;">L1 Data Cache</span>共用的<span style="font-family: "Times New Roman", serif;">Page</span>一致性<span style="font-family: "Times New Roman", serif;">.)</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>在多核心的架構下<span style="font-family: "Times New Roman", serif;">,ARM</span>為了減少每個處理器出去外部<span style="font-family: "Times New Roman", serif;">TLB</span>查詢<span style="font-family: "Times New Roman", serif;">Table</span>的次數<span style="font-family: "Times New Roman", serif;">,</span>因此提供了<span style="font-family: "Times New Roman", serif;">2 Level</span>的<span style="font-family: "Times New Roman", serif;">TLB</span>架構<span style="font-family: "Times New Roman", serif;">(Micro</span>與<span style="font-family: "Times New Roman", serif;">Main TLB),</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="border-collapse: collapse; color: black; font-size: 12.8px; margin: 10px 0px; width: 806px;"><colgroup><col width="152"></col><col width="632"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="152"><span style="font-family: "Times New Roman", serif;">Micro TLB</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="632">每個處理器都會有自己的<span style="font-family: "Times New Roman", serif;">Micro TLB,</span>提供<span style="font-family: "Times New Roman", serif;">Instruction</span>與<span style="font-family: "Times New Roman", serif;">Data</span>各<span style="font-family: "Times New Roman", serif;">32</span>筆對應的項目<span style="font-family: "Times New Roman", serif;">(ARM11 MPCore</span>為各八筆<span style="font-family: "Times New Roman", serif;">),</span>可以在<span style="font-family: "Times New Roman", serif;">1</span>個<span style="font-family: "Times New Roman", serif;">CPU Cycle</span>把<span style="font-family: "Times New Roman", serif;">Virtual Address</span>轉為<span style="font-family: "Times New Roman", serif;">Physical Address,</span>包括該記憶體分頁的保護屬性<span style="font-family: "Times New Roman", serif;">,</span>或是否要觸發<span style="font-family: "Times New Roman", serif;">Prefech/Data Abort.</span>如果該<span style="font-family: "Times New Roman", serif;">Virtual Address</span>不在這<span style="font-family: "Times New Roman", serif;">Instruction</span>或<span style="font-family: "Times New Roman", serif;">Data TLB </span>的紀錄中<span style="font-family: "Times New Roman", serif;">,</span>就會往<span style="font-family: "Times New Roman", serif;">Main TLB</span>查詢<span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果外部的<span style="font-family: "Times New Roman", serif;">Main TLB</span>有更新<span style="font-family: "Times New Roman", serif;">,</span>或是發生<span style="font-family: "Times New Roman", serif;">Task Context-Switch </span>更新<span style="font-family: "Times New Roman", serif;">Context ID Register</span>都會導致<span style="font-family: "Times New Roman", serif;">Micro TLB</span>被<span style="font-family: "Times New Roman", serif;">Flush.</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="152"><span style="font-family: "Times New Roman", serif;">Main TLB</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="632"><span style="font-family: "Times New Roman", serif;">Main TLB</span>可以對應到<span style="font-family: "Times New Roman", serif;">16MB,1MB,64KB</span>與<span style="font-family: "Times New Roman", serif;">4KB</span>不同的記憶體分頁<span style="font-family: "Times New Roman", serif;">,</span>一旦所要查詢的<span style="font-family: "Times New Roman", serif;">Virtual Address</span>在<span style="font-family: "Times New Roman", serif;">Micro TLB</span>中查詢不到<span style="font-family: "Times New Roman", serif;">,</span>就會到<span style="font-family: "Times New Roman", serif;">Main TLB</span>中查詢<span style="font-family: "Times New Roman", serif;">. Main TLB</span>為<span style="font-family: "Times New Roman", serif;">2 ways</span>的配置<span style="font-family: "Times New Roman", serif;">,</span>可以為<span style="font-family: "Times New Roman", serif;">2*32</span>的<span style="font-family: "Times New Roman", serif;">64</span>筆項目的<span style="font-family: "Times New Roman", serif;">Main TLB,</span>或<span style="font-family: "Times New Roman", serif;">2*64</span>的<span style="font-family: "Times New Roman", serif;">128</span>筆項目的<span style="font-family: "Times New Roman", serif;">Main TLB. </span>每個<span style="font-family: "Times New Roman", serif;">Main TLB</span>項目都會包括<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,Virtual Address</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,Page Size</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,Physical Address</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,Memory Properties</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每一組上述的項目<span style="font-family: "Times New Roman", serif;">,</span>都會對應到一個特定的<span style="font-family: "Times New Roman", serif;">Application</span>空間<span style="font-family: "Times New Roman", serif;">,</span>或是<span style="font-family: "Times New Roman", serif;">Global</span>讓全系統共享<span style="font-family: "Times New Roman", serif;">,</span>每個<span style="font-family: "Times New Roman", serif;">ARM</span>核心都會透過設定<span style="font-family: "Times New Roman", serif;">CONTEXIDR</span>暫存器<span style="font-family: "Times New Roman", serif;">,</span>記錄目前該核心所運作的<span style="font-family: "Times New Roman", serif;">Application</span>空間<span style="font-family: "Times New Roman", serif;">,</span>每次<span style="font-family: "Times New Roman", serif;">TLB</span>項目比對時<span style="font-family: "Times New Roman", serif;">,</span>只要符合以下條件就算是對比成功</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>虛擬記憶體跟<span style="font-family: "Times New Roman", serif;">TLB</span>項目一致 <span style="font-family: "Times New Roman", serif;">(bits</span>長度可為<span style="font-family: "Times New Roman", serif;">[31:N],</span>要視記憶體分頁大小而定<span style="font-family: "Times New Roman", serif;">)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,Non-secure TLB ID (NSTID)</span>跟目前<span style="font-family: "Times New Roman", serif;">Secure</span>狀態一致<span style="font-family: "Times New Roman", serif;">. (</span>在有支援<span style="font-family: "Times New Roman", serif;">Trust Zone Security Extension</span>的環境<span style="font-family: "Times New Roman", serif;">)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>跟<span style="font-family: "Times New Roman", serif;">TLB</span>中的<span style="font-family: "Times New Roman", serif;">ASID</span>跟目標<span style="font-family: "Times New Roman", serif;">Task ASID</span>一致或是為<span style="font-family: "Times New Roman", serif;">Global</span>數性<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其它有關<span style="font-family: "Times New Roman", serif;">Main TLB lockdown </span>相關暫存器<span style="font-family: "Times New Roman", serif;">,</span>如下所示</div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p15,5,<Rd>,c15,c4,2 #Select Lockdown TLB Entry for Read (Main TLB Index)</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p15,5,<Rd>,c15,c4,4 #Select Lockdown TLB Entry for Write (Main TLB Index)</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p15,5,<Rd>,c15,c5,2 #Read Lockdown TLB VA Register Data</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p15,5,<Rd>,c15,c5,2 #Write Lockdown TLB VA Register Data</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p15,5,<Rd>,c15,c6,2 #Read Lockdown TLB PA Register Data</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p15,5,<Rd>,c15,c6,2 #Write Lockdown TLB PA Register Data</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p15,5,<Rd>,c15,c7,2 #Read Lockdown TLB attributes Register Data</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p15,5,<Rd>,c15,c7,2 #Write Lockdown TLB attributes Register Data</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
</td></tr>
</tbody></table>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>結語</strong></span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>隨著<span style="font-family: "Times New Roman", serif;">Smart Phone</span>與平板市場的風行<span style="font-family: "Times New Roman", serif;">,ARM MPCore</span>架構絕對會是最受矚目的方案<span style="font-family: "Times New Roman", serif;">,</span>尤其<span style="font-family: "Times New Roman", serif;">,</span>包括<span style="font-family: "Times New Roman", serif;">Android</span>上用<span style="font-family: "Times New Roman", serif;">NDK</span>開發的應用<span style="font-family: "Times New Roman", serif;">,</span>或是其它基於<span style="font-family: "Times New Roman", serif;">ARM</span>平台的方案<span style="font-family: "Times New Roman", serif;">,</span>都讓<span style="font-family: "Times New Roman", serif;">ARM</span>處理器累積了大量專屬的應用與越來越難以取代的角色<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>本文主要以筆者所需的資訊為主來彙整<span style="font-family: "Times New Roman", serif;">,</span>對<span style="font-family: "Times New Roman", serif;">ARM MPCore</span>有更進一步需求的開發者<span style="font-family: "Times New Roman", serif;">,</span>請自行參閱<span style="font-family: "Times New Roman", serif;">ARM MPCore</span>技術文件<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><br /></span></div>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span>
<span style="font-size: 12.8px;"><span style="font-size: 12.8px;"><br /></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: 12.8px;"><br /></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com1tag:blogger.com,1999:blog-1668810802505961314.post-23302086835662977832017-06-01T09:57:00.001-07:002017-06-01T09:57:49.996-07:00Android筆記-Linux Kernel Ftrace (Function Trace)解析<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android筆記-Linux Kernel Ftrace (Function Trace)解析</h1>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Android</span><span style="font-family: "Times New Roman", serif;">筆記</span><span style="font-family: "Times New Roman", serif;">-Linux Kernel Ftrace (Function Trace)</span><span style="font-family: "Times New Roman", serif;">解析</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "Times New Roman", serif;">hlchou@mail2000.com.tw</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "Times New Roman", serif;">by loda</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">在軟體開發時</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">通常都會面臨到系統效能調教的需求</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我們希望知道哪些區塊的程式碼或函式被執行的次數頻繁</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">或是佔據較高的處理器時間</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以便藉此優化程式碼撰寫的行為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">或是改善耗</span><span style="font-family: "Times New Roman", serif;">CPU</span><span style="font-family: "Times New Roman", serif;">時間的算法</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以</span><span style="font-family: "Times New Roman", serif;">Linux</span><span style="font-family: "Times New Roman", serif;">平台來說</span><span style="font-family: "Times New Roman", serif;">,OProfile(<span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://oprofile.sourceforge.net/news/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://oprofile.sourceforge.net</a></span></span> )</span><span style="font-family: "Times New Roman", serif;">會是一個大家常推薦的工具</span><span style="font-family: "Times New Roman", serif;">,OProfile</span><span style="font-family: "Times New Roman", serif;">支持</span><span style="font-family: "Times New Roman", serif;">Time-based</span><span style="font-family: "Times New Roman", serif;">透過系統</span><span style="font-family: "Times New Roman", serif;">Timer</span><span style="font-family: "Times New Roman", serif;">中斷蒐集當下執行環境資訊</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">並加以統計</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">或基於</span><span style="font-family: "Times New Roman", serif;">Event-based,</span><span style="font-family: "Times New Roman", serif;">以</span><span style="font-family: "Times New Roman", serif;">ARM </span><span style="font-family: "Times New Roman", serif;">來說</span><span style="font-family: "Times New Roman", serif;">就是</span><span style="font-family: "Times New Roman", serif;">Performance Monitor Unit(CP15)</span><span style="font-family: "Times New Roman", serif;">硬體支援的</span><span style="font-family: "Times New Roman", serif;">Performance</span><span style="font-family: "Times New Roman", serif;">控制單元 </span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">更多資訊可以參考</span><span style="font-family: "Times New Roman", serif;">:http://infocenter.arm.com/help/topic/com.arm.doc.dai0195b/index.html),ARM PMU</span><span style="font-family: "Times New Roman", serif;">提供例如</span><span style="font-family: "Times New Roman", serif;">Instruction/Data Cache </span><span style="font-family: "Times New Roman", serif;">使用狀況</span><span style="font-family: "Times New Roman", serif;">(miss,write-back,write-buffer..etc)</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">Memory/MMU </span><span style="font-family: "Times New Roman", serif;">存取的狀況</span><span style="font-family: "Times New Roman", serif;">, IRQ/FIQ Latency,Branch</span><span style="font-family: "Times New Roman", serif;">預測統計</span><span style="font-family: "Times New Roman", serif;">,I/D-TCM Status..etc,</span><span style="font-family: "Times New Roman", serif;">基於這機制的</span><span style="font-family: "Times New Roman", serif;">Profiling</span><span style="font-family: "Times New Roman", serif;">可以在影響系統效能最少的情況下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">進行</span><span style="font-family: "Times New Roman", serif;">System-wide</span><span style="font-family: "Times New Roman", serif;">的性能統計資訊</span><span style="font-family: "Times New Roman", serif;">. </span><span style="font-family: "Times New Roman", serif;">另一種選擇</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">則是透過</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">接上</span><span style="font-family: "Times New Roman", serif;">JTAG</span><span style="font-family: "Times New Roman", serif;">介面</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">藉由</span><span style="font-family: "Times New Roman", serif;">ICE</span><span style="font-family: "Times New Roman", serif;">軟體的</span><span style="font-family: "Times New Roman", serif;">Profiling</span><span style="font-family: "Times New Roman", serif;">功能進行分析</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">然而</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如果我們希望更明確的知道每個</span><span style="font-family: "Times New Roman", serif;">Function</span><span style="font-family: "Times New Roman", serif;">被執行的次數 </span><span style="font-family: "Times New Roman", serif;">(OProfile Time-based</span><span style="font-family: "Times New Roman", serif;">的統計時間夠長就可得出對應的比例</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">做為決定的依據</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">執行的流程</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">與個別時間成本</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">或是系統在排程 </span><span style="font-family: "Times New Roman", serif;">(Scheduling and Wake-up),</span><span style="font-family: "Times New Roman", serif;">中斷</span><span style="font-family: "Times New Roman", serif;">,Block/Net,</span><span style="font-family: "Times New Roman", serif;">或</span><span style="font-family: "Times New Roman", serif;">Kernel</span><span style="font-family: "Times New Roman", serif;">記憶體配置</span><span style="font-family: "Times New Roman", serif;">..</span><span style="font-family: "Times New Roman", serif;">等</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">核心物件有關資訊的話</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">其實</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">會是另一個可以輔助的資訊來源</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">不同於</span><span style="font-family: "Times New Roman", serif;">OProfile,Ftrace</span><span style="font-family: "Times New Roman", serif;">會透過</span><span style="font-family: "Times New Roman", serif;">gcc -pg</span><span style="font-family: "Times New Roman", serif;">把每個函式前面都插入呼叫</span><span style="font-family: "Times New Roman", serif;">mcount</span><span style="font-family: "Times New Roman", serif;">函式的動作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在</span><span style="font-family: "Times New Roman", serif;">Branch</span><span style="font-family: "Times New Roman", serif;">統計部分</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">也會把</span><span style="font-family: "Times New Roman", serif;">if</span><span style="font-family: "Times New Roman", serif;">或是透過</span><span style="font-family: "Times New Roman", serif;">likely/unlikely</span><span style="font-family: "Times New Roman", serif;">巨集</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">進行植入是的統計</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">因此</span><span style="font-family: "Times New Roman", serif;">,Ftrace</span><span style="font-family: "Times New Roman", serif;">相比</span><span style="font-family: "Times New Roman", serif;">OProfile</span><span style="font-family: "Times New Roman", serif;">雖然可以提供比較完整的</span><span style="font-family: "Times New Roman", serif;">Kernel</span><span style="font-family: "Times New Roman", serif;">層級統計資訊</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">但因為</span><span style="font-family: "Times New Roman", serif;">OProfile</span><span style="font-family: "Times New Roman", serif;">主要是透過</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">或其他處理器平台的</span><span style="font-family: "Times New Roman", serif;">Performance Monitor</span><span style="font-family: "Times New Roman", serif;">單元</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">因此</span><span style="font-family: "Times New Roman", serif;">,OProfile</span><span style="font-family: "Times New Roman", serif;">可以在影響系統效能較低的情況下進行統計</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">ㄟ</span><span style="font-family: "Times New Roman", serif;">…Time-based Function profiling</span><span style="font-family: "Times New Roman", serif;">也是會影響到被測端的效能的</span><span style="font-family: "Times New Roman", serif;">.),</span><span style="font-family: "Times New Roman", serif;">但總體而言</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">都比</span><span style="font-family: "Times New Roman", serif;">mcount</span><span style="font-family: "Times New Roman", serif;">植入每個函式中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">對系統效能的影響更算是輕量</span><span style="font-family: "Times New Roman", serif;">. </span><span style="font-family: "Times New Roman", serif;">如何決定應用哪個模塊進行效能分析</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">還是要依據當下開發時的目的與所遇到的問題來做決定</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">最應該參考的文件就是</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">原始碼中位於</span><span style="font-family: "Times New Roman", serif;">Documentation/ftrace.txt</span><span style="font-family: "Times New Roman", serif;">的文件</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">參考該文件資訊與</span><span style="font-family: "Times New Roman", serif;">Google</span><span style="font-family: "Times New Roman", serif;">一下</span><span style="font-family: "Times New Roman", serif;">,Ftrace</span><span style="font-family: "Times New Roman", serif;">作者為在</span><span style="font-family: "Times New Roman", serif;">RedHat</span><span style="font-family: "Times New Roman", serif;">服務的 </span><span style="font-family: "Times New Roman", serif;">Steven Rostedt,</span><span style="font-family: "Times New Roman", serif;">主要目的是為</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">提供一個系統效能分析的工具</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以便用以除錯或是改善</span><span style="font-family: "Times New Roman", serif;">/</span><span style="font-family: "Times New Roman", serif;">優化系統效能</span><span style="font-family: "Times New Roman", serif;">,Ftrace</span><span style="font-family: "Times New Roman", serif;">為一個以</span><span style="font-family: "Times New Roman", serif;">Function Trace</span><span style="font-family: "Times New Roman", serif;">為基礎的工具</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">並包含了包括行程</span><span style="font-family: "Times New Roman", serif;">Context-Switch,Wake-Up/Ready</span><span style="font-family: "Times New Roman", serif;">到執行的時間成本</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">中斷關閉的時間</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以及是哪些函式呼叫所觸發的</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">這都有助於在複雜的系統執行下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">提供必要資訊以便定位問題</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">接下來</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我們將介紹</span><span style="font-family: "Times New Roman", serif;">GCC</span><span style="font-family: "Times New Roman", serif;">對於</span><span style="font-family: "Times New Roman", serif;">Ftrace Profiling</span><span style="font-family: "Times New Roman", serif;">上</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在編譯器層級的支援</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以及有關的</span><span style="font-family: "Times New Roman", serif;">builtin</span><span style="font-family: "Times New Roman", serif;">函式</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">讓各位清楚這些機制底層運作的原理</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">最後</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">並以</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">為主</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">說明個機制的內容</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">但本文並不會深入探究到各</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">模組機制的實作部分</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">主要只以筆者自己認為值得說明的區塊</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">來加以說明</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">對各項細節有興趣的開發者</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">建議可以自行探究</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>GCC “-pg” Profiling </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>機制與</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>builtin</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>函式對</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Ftrace Branch Profiling</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>的支援</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">支援在有加入 “</span><span style="font-family: "Times New Roman", serif;">likely/unlikely” </span><span style="font-family: "Times New Roman", serif;">條件判斷式位置的</span><span style="font-family: "Times New Roman", serif;">Brnch Profiling</span><span style="font-family: "Times New Roman", serif;">與對整個核心 </span><span style="font-family: "Times New Roman", serif;">if </span><span style="font-family: "Times New Roman", serif;">條件判斷式的</span><span style="font-family: "Times New Roman", serif;">Brnch Profiling (</span><span style="font-family: "Times New Roman", serif;">當然</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">選擇後者對效能影響也比較明顯</span><span style="font-family: "Times New Roman", serif;">…</span><span style="font-family: "Times New Roman", serif;">要做記錄的地方變多了</span><span style="font-family: "Times New Roman", serif;">.).</span><span style="font-family: "Times New Roman", serif;">使用者可以透過</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Branch Profiling —> </span><span style="font-family: "Times New Roman", serif;">來選擇“</span><span style="font-family: "Times New Roman", serif;">No branch profiling”,”Trace likely/unlikely profiler” </span><span style="font-family: "Times New Roman", serif;">或 “</span><span style="font-family: "Times New Roman", serif;">Profile all if conditionalss”. </span><span style="font-family: "Times New Roman", serif;">對系統進行</span><span style="font-family: "Times New Roman", serif;">Branch Profiling</span><span style="font-family: "Times New Roman", serif;">的動作</span><span style="font-family: "Times New Roman", serif;">. (Ftrace</span><span style="font-family: "Times New Roman", serif;">在 </span><span style="font-family: "Times New Roman", serif;">config</span><span style="font-family: "Times New Roman", serif;">中有這四個設定跟</span><span style="font-family: "Times New Roman", serif;">Branch Profiling</span><span style="font-family: "Times New Roman", serif;">有關</span><span style="font-family: "Times New Roman", serif;">CONFIG_TRACE_BRANCH_PROFILING,CONFIG_BRANCH_PROFILE_NONE,CONFIG_PROFILE_ANNOTATED_BRANCHES </span><span style="font-family: "Times New Roman", serif;">與 </span><span style="font-family: "Times New Roman", serif;">CONFIG_PROFILE_ALL_BRANCHES)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">參考</span><span style="font-family: "Times New Roman", serif;">include/linux/compiler.h</span><span style="font-family: "Times New Roman", serif;">中的實作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如果選擇“</span><span style="font-family: "Times New Roman", serif;">Profile all if conditionalss”,</span><span style="font-family: "Times New Roman", serif;">就會把全部的</span><span style="font-family: "Times New Roman", serif;">if</span><span style="font-family: "Times New Roman", serif;">條件判斷字元</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">透過</span><span style="font-family: "Times New Roman", serif;">gcc precompile</span><span style="font-family: "Times New Roman", serif;">定義為巨集 </span><span style="font-family: "Times New Roman", serif;">__trace_if,</span><span style="font-family: "Times New Roman", serif;">如下所示</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#define if(cond, …) __trace_if( (cond , ## __VA_ARGS__) )</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#define __trace_if(cond) \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">if (__builtin_constant_p((cond)) ? !!(cond) : \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">({ \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int ______r; \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">static struct ftrace_branch_data \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__attribute__((__aligned__(4))) \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__attribute__((section(“_ftrace_branch”))) \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">______f = { \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.func = __func__, \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.file = __FILE__, \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.line = __LINE__, \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}; \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">______r = !!(cond); \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">______f.miss_hit[______r]++; \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">______r; \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">如果</span><span style="font-family: "Times New Roman", serif;">if </span><span style="font-family: "Times New Roman", serif;">條件式為常數</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">也就是說編譯器可以在編譯階段就決定好</span><span style="font-family: "Times New Roman", serif;">if/else</span><span style="font-family: "Times New Roman", serif;">路徑了</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">就不納入統計</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">反之</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就會根據條件式的結果</span><span style="font-family: "Times New Roman", serif;">(______r =0 or 1)</span><span style="font-family: "Times New Roman", serif;">統計命中的次數</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">作為</span><span style="font-family: "Times New Roman", serif;">if/else</span><span style="font-family: "Times New Roman", serif;">條件設計的參考</span><span style="font-family: "Times New Roman", serif;">. (</span><span style="font-family: "Times New Roman", serif;">其實</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">透過</span><span style="font-family: "Times New Roman", serif;">likely/unlikely</span><span style="font-family: "Times New Roman", serif;">優化編譯階段的</span><span style="font-family: "Times New Roman", serif;">Branch Predition</span><span style="font-family: "Times New Roman", serif;">是很有幫助的</span><span style="font-family: "Times New Roman", serif;">).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">如果是設定為”</span><span style="font-family: "Times New Roman", serif;">Trace likely/unlikely profiler”,</span><span style="font-family: "Times New Roman", serif;">就會把 </span><span style="font-family: "Times New Roman", serif;">likely</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">unlikely</span><span style="font-family: "Times New Roman", serif;">巨集定義如下所示</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/*</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">* Using __builtin_constant_p(x) to ignore cases where the return</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">* value is always the same. This idea is taken from a similar patch</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">* written by Daniel Walker.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">*/</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># ifndef likely</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># define likely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 1))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># endif</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># ifndef unlikely</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># endif</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">其中</span><span style="font-family: "Times New Roman", serif;">__branch_check__</span><span style="font-family: "Times New Roman", serif;">定義如下</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#define likely_notrace(x) __builtin_expect(!!(x), 1)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#define unlikely_notrace(x) __builtin_expect(!!(x), 0)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#define __branch_check__(x, expect) ({ \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int ______r; \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">static struct ftrace_branch_data \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__attribute__((__aligned__(4))) \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__attribute__((section(“_ftrace_annotated_branch”))) \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">______f = { \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.func = __func__, \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.file = __FILE__, \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">.line = __LINE__, \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}; \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">______r = likely_notrace(x); \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ftrace_likely_update(&______f, ______r, expect); \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">______r; \</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">})</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">函式</span><span style="font-family: "Times New Roman", serif;">ftrace_likely_update (</span><span style="font-family: "Times New Roman", serif;">位置在</span><span style="font-family: "Times New Roman", serif;">kernel/trace/trace_branch.c)</span><span style="font-family: "Times New Roman", serif;">實作如下所示</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/*</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">* I would love to have a trace point here instead, but the</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">* trace point code is so inundated with unlikely and likely</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">* conditions that the recursive nightmare that exists is too</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">* much to try to get working. At least for now.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">*/</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">trace_likely_condition(f, val, expect);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">/* FIXME: Make this atomic! */</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">if (val == expect)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">f->correct++;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">else</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">f->incorrect++;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">有關函式 </span><span style="font-family: "Times New Roman", serif;">trace_likely_condition</span><span style="font-family: "Times New Roman", serif;">的行為在此就不追蹤</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">只談函式</span><span style="font-family: "Times New Roman", serif;">ftrace_likely_update,</span><span style="font-family: "Times New Roman", serif;">這函式會統計開發者使用</span><span style="font-family: "Times New Roman", serif;">likely/unlikely</span><span style="font-family: "Times New Roman", serif;">定義好的</span><span style="font-family: "Times New Roman", serif;">if/else</span><span style="font-family: "Times New Roman", serif;">區塊順序</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">跟實際執行時</span><span style="font-family: "Times New Roman", serif;">,if/else</span><span style="font-family: "Times New Roman", serif;">執行的結果</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">透過 </span><span style="font-family: "Times New Roman", serif;">correct/incorrect</span><span style="font-family: "Times New Roman", serif;">累加</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我們可以根據</span><span style="font-family: "Times New Roman", serif;">Run-Time</span><span style="font-family: "Times New Roman", serif;">實際統計的結果</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">看是否原本</span><span style="font-family: "Times New Roman", serif;">likely/unlikely</span><span style="font-family: "Times New Roman", serif;">有需要修正的空間</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">往統計正確的方向去</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就可避免處理器</span><span style="font-family: "Times New Roman", serif;">Pipeline Flush</span><span style="font-family: "Times New Roman", serif;">的機會</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">以便得到更好的執行效能</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">若沒有啟動任何</span><span style="font-family: "Times New Roman", serif;">Branch Profiling</span><span style="font-family: "Times New Roman", serif;">的動作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">則</span><span style="font-family: "Times New Roman", serif;">likely</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">unlikely</span><span style="font-family: "Times New Roman", serif;">就只會透過</span><span style="font-family: "Times New Roman", serif;">Builtin</span><span style="font-family: "Times New Roman", serif;">函式</span><span style="font-family: "Times New Roman", serif;">_builtin_expect (</span><span style="font-family: "Times New Roman", serif;">在</span><span style="font-family: "Times New Roman", serif;">GCC 2.96</span><span style="font-family: "Times New Roman", serif;">版本之後支援</span><span style="font-family: "Times New Roman", serif;">)</span><span style="font-family: "Times New Roman", serif;">進行編譯階段的</span><span style="font-family: "Times New Roman", serif;">Branch Predition</span><span style="font-family: "Times New Roman", serif;">優化動作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如下宣告</span><span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># define likely(x) __builtin_expect(!!(x), 1)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># define unlikely(x) __builtin_expect(!!(x), 0)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">編譯器支援的</span><span style="font-family: "Times New Roman", serif;">Builtin</span><span style="font-family: "Times New Roman", serif;">函式</span><span style="font-family: "Times New Roman", serif;">__builtin_constant_p,</span><span style="font-family: "Times New Roman", serif;">主要的功能為判斷所給予的值是否為常數</span><span style="font-family: "Times New Roman", serif;">(__builtin_constant_p</span><span style="font-family: "Times New Roman", serif;">會返回</span><span style="font-family: "Times New Roman", serif;">1,</span><span style="font-family: "Times New Roman", serif;">若不是常數</span><span style="font-family: "Times New Roman", serif;">__builtin_constant_p</span><span style="font-family: "Times New Roman", serif;">會返回</span><span style="font-family: "Times New Roman", serif;">0),</span><span style="font-family: "Times New Roman", serif;">若是則可在編譯時期安排好對應的執行動作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就不需要把全部的行為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">都放到編譯後的程式碼</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">透過執行時期才決定</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">以如下程式碼來驗證行為</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#define Y 6</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">void Func(int Z)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int vResult;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vResult=__builtin_constant_p(Z)?(Z*100):-1;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“5:Result:%ld\n”,vResult);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vResult=(Z*100);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“6:Result:%ld\n”,vResult);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int main()</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int X=5;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int vResult;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vResult=__builtin_constant_p(X)?(X*100):-1;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“1:Result:%ld\n”,vResult);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vResult=(X*100);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“2:Result:%ld\n”,vResult);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vResult=__builtin_constant_p(Y)?(Y*100):-1;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“3:Result:%ld\n”,vResult);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vResult=(Y*100);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“4:Result:%ld\n”,vResult);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Func(7);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">return;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">以</span><span style="font-family: "Times New Roman", serif;">gcc</span><span style="font-family: "Times New Roman", serif;">版本</span><span style="font-family: "Times New Roman", serif;">4.1.2</span><span style="font-family: "Times New Roman", serif;">來驗證</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">若以</span><span style="font-family: "Times New Roman", serif;">-O0</span><span style="font-family: "Times New Roman", serif;">編譯</span><span style="font-family: "Times New Roman", serif;">,X</span><span style="font-family: "Times New Roman", serif;">為一個區域變數</span><span style="font-family: "Times New Roman", serif;">,__builtin_constant_p(X)</span><span style="font-family: "Times New Roman", serif;">會返回</span><span style="font-family: "Times New Roman", serif;">0,</span><span style="font-family: "Times New Roman", serif;">反之</span><span style="font-family: "Times New Roman", serif;">,Y</span><span style="font-family: "Times New Roman", serif;">為一個定義的常數</span><span style="font-family: "Times New Roman", serif;">,__builtin_constant_p(Y)</span><span style="font-family: "Times New Roman", serif;">會返回</span><span style="font-family: "Times New Roman", serif;">1,</span><span style="font-family: "Times New Roman", serif;">而如果把一個常數透過函式參數</span><span style="font-family: "Times New Roman", serif;">Z</span><span style="font-family: "Times New Roman", serif;">傳遞</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">因為這個值會被放到堆疊</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">根據每個處理器的</span><span style="font-family: "Times New Roman", serif;">Calling Convention,</span><span style="font-family: "Times New Roman", serif;">在</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">上會先放到暫存器</span><span style="font-family: "Times New Roman", serif;">R0-R3),</span><span style="font-family: "Times New Roman", serif;">導致</span><span style="font-family: "Times New Roman", serif;">__builtin_constant_p(Z)</span><span style="font-family: "Times New Roman", serif;">返回</span><span style="font-family: "Times New Roman", serif;">0,</span><span style="font-family: "Times New Roman", serif;">若是以</span><span style="font-family: "Times New Roman", serif;">-O1</span><span style="font-family: "Times New Roman", serif;">或</span><span style="font-family: "Times New Roman", serif;">-O2</span><span style="font-family: "Times New Roman", serif;">編譯</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">則編譯器可以判斷區域變數</span><span style="font-family: "Times New Roman", serif;">X</span><span style="font-family: "Times New Roman", serif;">的值</span><span style="font-family: "Times New Roman", serif;">,__builtin_constant_p(X)</span><span style="font-family: "Times New Roman", serif;">會返回</span><span style="font-family: "Times New Roman", serif;">1,</span><span style="font-family: "Times New Roman", serif;">若是函式函式傳遞的參數</span><span style="font-family: "Times New Roman", serif;">Z,_builtin_constant_p(Z)</span><span style="font-family: "Times New Roman", serif;">還是會傳回</span><span style="font-family: "Times New Roman", serif;">0. </span><span style="font-family: "Times New Roman", serif;">優化的區塊還是以</span><span style="font-family: "Times New Roman", serif;">Function</span><span style="font-family: "Times New Roman", serif;">本身為單位</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">並且有打開優化選項</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">可以讓</span><span style="font-family: "Times New Roman", serif;">Builtin</span><span style="font-family: "Times New Roman", serif;">函式發揮更好的效能</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">參考</span><span style="font-family: "Times New Roman", serif;">GCC</span><span style="font-family: "Times New Roman", serif;">文件</span><span style="font-family: "Times New Roman", serif;">,__builtin_constant_p</span><span style="font-family: "Times New Roman", serif;">也可以作為</span><span style="font-family: "Times New Roman", serif;">Constant</span><span style="font-family: "Times New Roman", serif;">變數初始值的指定</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">文件建議要在</span><span style="font-family: "Times New Roman", serif;">GCC 3.0.1</span><span style="font-family: "Times New Roman", serif;">版本之後</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">如下所示</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">若 </span><span style="font-family: "Times New Roman", serif;">EXPRESSION</span><span style="font-family: "Times New Roman", serif;">為常數</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">則</span><span style="font-family: "Times New Roman", serif;">table</span><span style="font-family: "Times New Roman", serif;">初始值為該常數</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">反之則初始值為</span><span style="font-family: "Times New Roman", serif;">0.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">static const int table[] = {</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">};</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">另一個需要介紹的</span><span style="font-family: "Times New Roman", serif;">Builtin</span><span style="font-family: "Times New Roman", serif;">函式為 </span><span style="font-family: "Times New Roman", serif;">__builtin_expect,</span><span style="font-family: "Times New Roman", serif;">這函式的功能主要在提供編譯器</span><span style="font-family: "Times New Roman", serif;">Branch Prediction</span><span style="font-family: "Times New Roman", serif;">的能力</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如以下的程式碼</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">void FuncA(int X)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">if(__builtin_expect(X,1))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“FuncA 1:%ld\n”,X*0x100);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">else</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“FuncA 2:%ld\n”,X);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">void FuncB(int X)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">if(__builtin_expect(X,0))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“FuncB 1:%ld\n”,X*0x100);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">else</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“FuncB 2:%ld\n”,X);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int main()</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">FuncA(7);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">FuncB(8);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">return;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">執行結果為</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">FuncA 1:700h</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">FuncB 1:800h</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">以</span><span style="font-family: "Times New Roman", serif;">gcc 4.1.2</span><span style="font-family: "Times New Roman", serif;">搭配</span><span style="font-family: "Times New Roman", serif;">-O2</span><span style="font-family: "Times New Roman", serif;">進行編譯</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">在這驗證環境下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">使用</span><span style="font-family: "Times New Roman", serif;">-O0,</span><span style="font-family: "Times New Roman", serif;">函式</span><span style="font-family: "Times New Roman", serif;">__builtin_expect</span><span style="font-family: "Times New Roman", serif;">會沒有效果</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">執行結果一致</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">透過反組譯程式碼結果如下</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 647px;"><colgroup><col width="187"></col><col width="222"></col><col width="213"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="187"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">FuncA/B (-O0)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="222"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">FuncA (-O2) – if(__builtin_expect(X,1))</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">FuncB(-O2)-if(__builtin_expect(X,0))</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="187"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x8,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0x8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">test %eax,%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">je </span><span style="font-size: xx-small;"><strong>80483a9</strong></span><span style="font-size: xx-small;"> <FuncA+0x25></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0x8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">shl $0x8,%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0x4(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x8048500,(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 8048298 <printf@plt></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jmp 80483bc <FuncA+0x38></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>80483a9:</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0x8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0x4(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x804850d,(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 8048298 <printf@plt></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">leave</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="222"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x8,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0x8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">test %eax,%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">je </span><span style="font-size: xx-small;"><strong>80483f2</strong></span><span style="font-size: xx-small;"> <FuncA+0x22></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>shl $0x8,%eax</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>mov %eax,0x4(%esp)</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>movl $0x804853a,(%esp)</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>call 8048298 <printf@plt></strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>leave</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ret</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>80483f2 :</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0x4(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x8048547,(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 8048298 <printf@plt></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">leave</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x8,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0x8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">test %eax,%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jne </span><span style="font-size: xx-small;"><strong>80483b3</strong></span><span style="font-size: xx-small;"> <FuncB+0x23></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>movl $0x0,0x4(%esp)</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>movl $0x804852d,(%esp)</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>call 8048298 <printf@plt></strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>leave</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ret</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>80483b3 :</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">shl $0x8,%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0x4(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x8048520,(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 8048298 <printf@plt></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">leave</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">我們可以看到</span><span style="font-family: "Times New Roman", serif;">__builtin_expect(X,1)</span><span style="font-family: "Times New Roman", serif;">會優先把</span><span style="font-family: "Times New Roman", serif;">if</span><span style="font-family: "Times New Roman", serif;">的執行區塊放到連續的程式碼中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">而</span><span style="font-family: "Times New Roman", serif;">__builtin_expect(X,0)</span><span style="font-family: "Times New Roman", serif;">則是會把 </span><span style="font-family: "Times New Roman", serif;">else</span><span style="font-family: "Times New Roman", serif;">的執行區塊</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">放到前面連續的程式碼中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">至於執行時期會執行到</span><span style="font-family: "Times New Roman", serif;">if</span><span style="font-family: "Times New Roman", serif;">或</span><span style="font-family: "Times New Roman", serif;">else</span><span style="font-family: "Times New Roman", serif;">的區塊</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就根據</span><span style="font-family: "Times New Roman", serif;">X</span><span style="font-family: "Times New Roman", serif;">條件是否為</span><span style="font-family: "Times New Roman", serif;">0</span><span style="font-family: "Times New Roman", serif;">來決定</span><span style="font-family: "Times New Roman", serif;">.</span><span style="font-family: "Times New Roman", serif;">參考</span><span style="font-family: "Times New Roman", serif;">GCC</span><span style="font-family: "Times New Roman", serif;">文件</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我們也可以搭配條件判斷的寫法</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">可以參考</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">include/linux/compiler.h</span><span style="font-family: "Times New Roman", serif;">中的實作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如下所示</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># define likely(x) __builtin_expect(!!(x), 1)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># define unlikely(x) __builtin_expect(!!(x), 0)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">如果開發者判斷</span><span style="font-family: "Times New Roman", serif;">,if</span><span style="font-family: "Times New Roman", serif;">的區塊是較常被執行到的</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">那就應該用</span><span style="font-family: "Times New Roman", serif;">likely,</span><span style="font-family: "Times New Roman", serif;">例如</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">if (likely(success))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{….}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">else <span style="color: red;"><span style="text-decoration-line: underline;"><strong>//else</strong></span></span></span><span style="color: red;"><span style="text-decoration-line: underline;"><span style="font-family: "Times New Roman", serif;"><strong>區塊可能為</strong></span><span style="font-family: "Times New Roman", serif;"><strong>error</strong></span></span></span><span style="color: red;"><span style="text-decoration-line: underline;"><span style="font-family: "Times New Roman", serif;"><strong>處理邏輯</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span></span></span><span style="color: red;"><span style="text-decoration-line: underline;"><span style="font-family: "Times New Roman", serif;"><strong>多數的情況應該希望走的是</strong></span><span style="font-family: "Times New Roman", serif;"><strong>if</strong></span></span></span><span style="color: red;"><span style="text-decoration-line: underline;"><span style="font-family: "Times New Roman", serif;"><strong>的邏輯</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{….}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">如果開發者判斷</span><span style="font-family: "Times New Roman", serif;">else</span><span style="font-family: "Times New Roman", serif;">區塊</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">是希望較常被執行到的</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就可以使用</span><span style="font-family: "Times New Roman", serif;">unlikely,</span><span style="font-family: "Times New Roman", serif;">例如</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">if (unlikely(error))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{….}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">else <span style="color: red;"><strong>//success</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{….}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">處理器本身也有</span><span style="font-family: "Times New Roman", serif;">Branch Predition</span><span style="font-family: "Times New Roman", serif;">的能力</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如果不在有被處理器記憶到的</span><span style="font-family: "Times New Roman", serif;">BP Entry</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">處理器通常會</span><span style="font-family: "Times New Roman", serif;">循序</span><span style="font-family: "Times New Roman", serif;">Fetch</span><span style="font-family: "Times New Roman", serif;">指令進來</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">一旦發現分支預測錯誤</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就會</span><span style="font-family: "Times New Roman", serif;">Flush Pipeline,</span><span style="font-family: "Times New Roman", serif;">透過函式</span><span style="font-family: "Times New Roman", serif;">__builtin_expect,</span><span style="font-family: "Times New Roman", serif;">我們可以在編譯時期</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">依據傳入值的結果</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">決定 </span><span style="font-family: "Times New Roman", serif;">if/else</span><span style="font-family: "Times New Roman", serif;">編譯為機械碼時程式碼排列的順序</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">減少處理器</span><span style="font-family: "Times New Roman", serif;">Pipeline</span><span style="font-family: "Times New Roman", serif;">被</span><span style="font-family: "Times New Roman", serif;">Flush</span><span style="font-family: "Times New Roman", serif;">的機率</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">這對執行效能也是有很大的幫助</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>GCC support for the GNU profiler gprof</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">有關</span><span style="font-family: "Times New Roman", serif;">GNU gprof</span><span style="font-family: "Times New Roman", serif;">的介紹</span><span style="font-family: "Times New Roman", serif;">, </span><span style="font-family: "Times New Roman", serif;">可以參考網頁</span><span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html</a></span></span> .</span><span style="font-family: "Times New Roman", serif;">基於</span><span style="font-family: "Times New Roman", serif;">GCC</span><span style="font-family: "Times New Roman", serif;">對</span><span style="font-family: "Times New Roman", serif;">Profiling</span><span style="font-family: "Times New Roman", serif;">的支援</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">開發端可以透過 </span><span style="font-family: "Times New Roman", serif;">-pg </span><span style="font-family: "Times New Roman", serif;">的編譯參數</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">讓</span><span style="font-family: "Times New Roman", serif;">gcc </span><span style="font-family: "Times New Roman", serif;">把</span><span style="font-family: "Times New Roman", serif;">profiling</span><span style="font-family: "Times New Roman", serif;">的功能加入到程式碼中</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">以如下程式碼為例</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int FuncA()</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int i;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int vRet=0;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">for(i=0;i<20000;i++)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vRet+=i;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">return vRet;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int FuncB(int I)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int i;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int vRet=0;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">for(i=0;i<9999;i++)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vRet+=I+FuncA();</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">return vRet;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int main()</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">int vResult;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vResult=FuncA();</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">vResult=FuncB(vResult);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">printf(“Result:%ld\n”,vResult);</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">return 0;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">}</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">透過</span><span style="font-family: "Times New Roman", serif;">gcc</span><span style="font-family: "Times New Roman", serif;">編譯後</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">有加上 </span><span style="font-family: "Times New Roman", serif;">-pg </span><span style="font-family: "Times New Roman", serif;">與沒加上的差異如下</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 648px;"><colgroup><col width="102"></col><col width="177"></col><col width="343"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="102"><span style="font-family: "Times New Roman", serif;">函式名稱</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "Times New Roman", serif;">無</span><span style="font-family: "Times New Roman", serif;">-pg</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"><span style="font-family: "Times New Roman", serif;">有加上</span><span style="font-family: "Times New Roman", serif;">-pg</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="102"><span style="font-family: "Times New Roman", serif;">main</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">lea 0x4(%esp),%ecx</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">and $0xfffffff0,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">pushl 0xfffffffc(%ecx)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ecx</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x24,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 8048384 <FuncA></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffff8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 80483b2 <FuncB></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffff8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0x4(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x8048500,(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 8048298 <printf@plt></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov $0x0,%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add $0x24,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">pop %ecx</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">pop %ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">lea 0xfffffffc(%ecx),%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">lea 0x4(%esp),%ecx</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">and $0xfffffff0,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">pushl 0xfffffffc(%ecx)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ecx</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x24,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><span style="font-size: xx-small;"><strong>call 804837c <mcount@plt> =>Glibc</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>提供的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>mcount</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>函式</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 80484b4 <FuncA></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffff8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 80484e7 <FuncB></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffff8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %eax,0x4(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x8048680,(%esp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 804835c <printf@plt></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov $0x0,%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add $0x24,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">pop %ecx</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">pop %ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">lea 0xfffffffc(%ecx),%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="102"><span style="font-family: "Times New Roman", serif;">FuncA</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x10,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0xfffffffc(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jmp 80483a4 <FuncA+0x20></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffff8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add %eax,0xfffffffc(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">addl $0x1,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cmpl $0x4e1f,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jle 804839a <FuncA+0x16></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffffc(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">leave</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x10,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><span style="font-size: xx-small;"><strong>call 804837c <mcount@plt> =>Glibc</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>提供的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>mcount</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>函式</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0xfffffffc(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jmp 80484d9 <FuncA+0x25></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffff8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add %eax,0xfffffffc(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">addl $0x1,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cmpl $0x4e1f,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jle 80484cf <FuncA+0x1b></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffffc(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">leave</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td></tr>
<tr valign="TOP"><td height="15" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="102"><span style="font-family: "Times New Roman", serif;">FuncB</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x10,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0xfffffffc(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jmp 80483d7 <FuncB+0x25></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 8048384 <FuncA></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add 0x8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add %eax,0xfffffffc(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">addl $0x1,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cmpl $0x270e,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jle 80483c8 <FuncB+0x16></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffffc(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">leave</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="343"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push %ebp</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov %esp,%ebp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub $0x10,%esp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><span style="font-size: xx-small;"><strong>call 804837c <mcount@plt> =>Glibc</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>提供的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>mcount</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>函式</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0xfffffffc(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movl $0x0,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jmp 8048511 <FuncB+0x2a></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">call 80484b4 <FuncA></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add 0x8(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add %eax,0xfffffffc(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">addl $0x1,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cmpl $0x270e,0xfffffff8(%ebp)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">jle 8048502 <FuncB+0x1b></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov 0xfffffffc(%ebp),%eax</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">leave</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ret</span></span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[root@localhost pg]# gcc -g -pg pg.c -o pg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[root@localhost pg]# ./pg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Result:785467424</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[root@localhost pg]# ls -l gmon.out</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">-rw-r–r– 1 root root 464 May 13 06:32 gmon.out</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[root@localhost pg]# gprof –brief ./pg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[root@localhost pg]# gprof –brief ./pg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Flat profile:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Each sample counts as 0.01 seconds.</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 647px;"><colgroup><col width="83"></col><col width="84"></col><col width="84"></col><col width="84"></col><col width="84"></col><col width="84"></col><col width="87"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">% time</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">cumulative (seconds)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">self (seconds)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">calls</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">Self (ms/call)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">Total (ms/call)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><span style="font-family: "Times New Roman", serif;">name</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">100.54</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">10000</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">0.05</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">0.05</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><span style="font-family: "Times New Roman", serif;">FuncA</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="84"><span style="font-family: "Times New Roman", serif;">472.49</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><span style="font-family: "Times New Roman", serif;">FuncB</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>=></strong></span><span style="font-family: "Times New Roman", serif;"><strong>簡要說明</strong></span><span style="font-family: "Times New Roman", serif;"><strong>: </strong></span><span style="font-family: "Times New Roman", serif;"><strong>每次呼叫</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA</strong></span><span style="font-family: "Times New Roman", serif;"><strong>需要</strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.05ms,</strong></span><span style="font-family: "Times New Roman", serif;"><strong>總共呼叫了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>10000</strong></span><span style="font-family: "Times New Roman", serif;"><strong>次</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span><span style="font-family: "Times New Roman", serif;"><strong>耗時</strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.47</strong></span><span style="font-family: "Times New Roman", serif;"><strong>秒 </strong></span><span style="font-family: "Times New Roman", serif;"><strong>(</strong></span><span style="font-family: "Times New Roman", serif;"><strong>ㄟ 也許應該說每次呼叫</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA</strong></span><span style="font-family: "Times New Roman", serif;"><strong>需要</strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.047ms</strong></span><span style="font-family: "Times New Roman", serif;"><strong>會比較精確一點</strong></span><span style="font-family: "Times New Roman", serif;"><strong>),</strong></span><span style="font-family: "Times New Roman", serif;"><strong>而</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FnucB</strong></span><span style="font-family: "Times New Roman", serif;"><strong>被呼叫</strong></span><span style="font-family: "Times New Roman", serif;"><strong>1</strong></span><span style="font-family: "Times New Roman", serif;"><strong>次</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span><span style="font-family: "Times New Roman", serif;"><strong>耗時</strong></span><span style="font-family: "Times New Roman", serif;"><strong>472.49ms (</strong></span><span style="font-family: "Times New Roman", serif;"><strong>在</strong></span><span style="font-family: "Times New Roman", serif;"><strong>funcB</strong></span><span style="font-family: "Times New Roman", serif;"><strong>中會執行</strong></span><span style="font-family: "Times New Roman", serif;"><strong>9999</strong></span><span style="font-family: "Times New Roman", serif;"><strong>次</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA).</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Call graph</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">granularity: each sample hit covers 2 byte(s) for 2.12% of 0.47 seconds</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 647px;"><colgroup><col width="98"></col><col width="99"></col><col width="99"></col><col width="99"></col><col width="99"></col><col width="103"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">index</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">% time</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">self</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">children</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">called</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">name</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">1/10000</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">main [2]</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">9999/10000</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">FuncB [3]</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">[1]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">100</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">10000</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">FuncA [1]</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>=></strong></span><span style="font-family: "Times New Roman", serif;"><strong>簡要說明</strong></span><span style="font-family: "Times New Roman", serif;"><strong>: </strong></span><span style="font-family: "Times New Roman", serif;"><strong>以</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA</strong></span><span style="font-family: "Times New Roman", serif;"><strong>為主體來對比</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,FuncA</strong></span><span style="font-family: "Times New Roman", serif;"><strong>執行了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>10000</strong></span><span style="font-family: "Times New Roman", serif;"><strong>次共</strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.47</strong></span><span style="font-family: "Times New Roman", serif;"><strong>秒的時間</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,FuncB</strong></span><span style="font-family: "Times New Roman", serif;"><strong>呼叫了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA 9999 (</strong></span><span style="font-family: "Times New Roman", serif;"><strong>佔總數</strong></span><span style="font-family: "Times New Roman", serif;"><strong>9999/10000), main</strong></span><span style="font-family: "Times New Roman", serif;"><strong>呼叫了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA 1</strong></span><span style="font-family: "Times New Roman", serif;"><strong>次 </strong></span><span style="font-family: "Times New Roman", serif;"><strong>(</strong></span><span style="font-family: "Times New Roman", serif;"><strong>佔總數</strong></span><span style="font-family: "Times New Roman", serif;"><strong>1/10000)</strong></span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 647px;"><colgroup><col width="98"></col><col width="99"></col><col width="99"></col><col width="99"></col><col width="99"></col><col width="103"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">index</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">% time</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">self</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">children</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">called</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">name</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">[2]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">100</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">main [2]</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">FuncB [3]</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">1/10000</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">FuncA [1]</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>=></strong></span><span style="font-family: "Times New Roman", serif;"><strong>簡要說明</strong></span><span style="font-family: "Times New Roman", serif;"><strong>: </strong></span><span style="font-family: "Times New Roman", serif;"><strong>以</strong></span><span style="font-family: "Times New Roman", serif;"><strong>main</strong></span><span style="font-family: "Times New Roman", serif;"><strong>為主體來對比</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,main</strong></span><span style="font-family: "Times New Roman", serif;"><strong>呼叫的函式</strong></span><span style="font-family: "Times New Roman", serif;"><strong>(children)</strong></span><span style="font-family: "Times New Roman", serif;"><strong>花了 </strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.47</strong></span><span style="font-family: "Times New Roman", serif;"><strong>秒</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span><span style="font-family: "Times New Roman", serif;"><strong>分別呼叫了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncB </strong></span><span style="font-family: "Times New Roman", serif;"><strong>佔了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>9999/10000(</strong></span><span style="font-family: "Times New Roman", serif;"><strong>約等於</strong></span><span style="font-family: "Times New Roman", serif;"><strong>1)</strong></span><span style="font-family: "Times New Roman", serif;"><strong>的時間</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span><span style="font-family: "Times New Roman", serif;"><strong>與呼叫了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA</strong></span><span style="font-family: "Times New Roman", serif;"><strong>佔了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>1/10000</strong></span><span style="font-family: "Times New Roman", serif;"><strong>的時間</strong></span><span style="font-family: "Times New Roman", serif;"><strong>.</strong></span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 647px;"><colgroup><col width="98"></col><col width="99"></col><col width="99"></col><col width="99"></col><col width="99"></col><col width="103"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">index</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">% time</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">self</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">children</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">called</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">name</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">main [2]</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">[3]</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">100</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">FuncB [3]</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0.47</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="99"><span style="font-family: "Times New Roman", serif;">9999/10000</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">FuncA [1]</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>=></strong></span><span style="font-family: "Times New Roman", serif;"><strong>簡要說明</strong></span><span style="font-family: "Times New Roman", serif;"><strong>: </strong></span><span style="font-family: "Times New Roman", serif;"><strong>以</strong></span><span style="font-family: "Times New Roman", serif;"><strong>funcB</strong></span><span style="font-family: "Times New Roman", serif;"><strong>為主體來對比</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,main</strong></span><span style="font-family: "Times New Roman", serif;"><strong>呼叫的函式</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA </strong></span><span style="font-family: "Times New Roman", serif;"><strong>與</strong></span><span style="font-family: "Times New Roman", serif;"><strong>funcB(children)</strong></span><span style="font-family: "Times New Roman", serif;"><strong>花了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.47</strong></span><span style="font-family: "Times New Roman", serif;"><strong>秒</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,FuncB</strong></span><span style="font-family: "Times New Roman", serif;"><strong>呼叫的函式</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncA</strong></span><span style="font-family: "Times New Roman", serif;"><strong>花了</strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.47</strong></span><span style="font-family: "Times New Roman", serif;"><strong>秒 </strong></span><span style="font-family: "Times New Roman", serif;"><strong>(</strong></span><span style="font-family: "Times New Roman", serif;"><strong>因為最小單位為</strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.01</strong></span><span style="font-family: "Times New Roman", serif;"><strong>秒</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span><span style="font-family: "Times New Roman", serif;"><strong>太接近的兩個數字如果差距是在</strong></span><span style="font-family: "Times New Roman", serif;"><strong>0.01</strong></span><span style="font-family: "Times New Roman", serif;"><strong>秒以內</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span><span style="font-family: "Times New Roman", serif;"><strong>數字就有機會變成一樣</strong></span><span style="font-family: "Times New Roman", serif;"><strong>),FuncB</strong></span><span style="font-family: "Times New Roman", serif;"><strong>被呼叫</strong></span><span style="font-family: "Times New Roman", serif;"><strong>1</strong></span><span style="font-family: "Times New Roman", serif;"><strong>次</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,FuncA</strong></span><span style="font-family: "Times New Roman", serif;"><strong>被</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FuncB</strong></span><span style="font-family: "Times New Roman", serif;"><strong>呼叫</strong></span><span style="font-family: "Times New Roman", serif;"><strong>9999</strong></span><span style="font-family: "Times New Roman", serif;"><strong>次</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Index by function name</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[1] FuncA [3] FuncB</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Infrastructure for profiling code inserted by ‘gcc -pg’.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_80.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.network-theory.co.uk/docs/gccintro/gccintro_80.html</a></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>在</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Linux Kernel</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>中</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Enable Tracer</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">要在核心中支援</span><span style="font-family: "Times New Roman", serif;">Ftrace,</span><span style="font-family: "Times New Roman", serif;">除了</span><span style="font-family: "Times New Roman", serif;">GCC</span><span style="font-family: "Times New Roman", serif;">編譯器要支援</span><span style="font-family: "Times New Roman", serif;">-pg</span><span style="font-family: "Times New Roman", serif;">外</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">所採用的</span><span style="font-family: "Times New Roman", serif;">C</span><span style="font-family: "Times New Roman", serif;">函式庫也要支援相關</span><span style="font-family: "Times New Roman", serif;">mcount</span><span style="font-family: "Times New Roman", serif;">的函式</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">筆者用</span><span style="font-family: "Times New Roman", serif;">Android SDK</span><span style="font-family: "Times New Roman", serif;">帶的</span><span style="font-family: "Times New Roman", serif;">arm-eabi-gcc 4.4.0</span><span style="font-family: "Times New Roman", serif;">會產生編譯錯誤“</span><span style="font-family: "Times New Roman", serif;">undefined reference to `__gnu_mcount_nc’ “. </span><span style="font-family: "Times New Roman", serif;">筆者後來是到 </span><span style="font-family: "Times New Roman", serif;">Sourcery </span><span style="font-family: "Times New Roman", serif;">網址 </span><span style="font-family: "Times New Roman", serif;">http://www.codesourcery.com/sgpp/lite/arm/portal/subscription3053 </span><span style="font-family: "Times New Roman", serif;">下載</span><span style="font-family: "Times New Roman", serif;">arm-2007q3</span><span style="font-family: "Times New Roman", serif;">版本的編譯器與函式庫環境</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以此為基礎進行</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">環境</span><span style="font-family: "Times New Roman", serif;">Linux Kernel </span><span style="font-family: "Times New Roman", serif;">開啟</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">的編譯</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就可以解決無法</span><span style="font-family: "Times New Roman", serif;">Link ‘__gnu_mcount_nc’</span><span style="font-family: "Times New Roman", serif;">的錯誤了</span><span style="font-family: "Times New Roman", serif;">. (</span><span style="font-family: "Times New Roman", serif;">有關編譯環境與</span><span style="font-family: "Times New Roman", serif;">Kernel Source Code</span><span style="font-family: "Times New Roman", serif;">版本的選擇</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">會隨著版本演進而有所差異</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如有遇到編譯錯誤發生時</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">還請以各位自己所選擇的環境為主來判斷</span><span style="font-family: "Times New Roman", serif;">.)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">接下來執行 </span><span style="font-family: "Times New Roman", serif;">make menuconfig.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">如果是在</span><span style="font-family: "Times New Roman", serif;">x86</span><span style="font-family: "Times New Roman", serif;">的機器上</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">要</span><span style="font-family: "Times New Roman", serif;">Enable “Kernel Function Graph Trace”</span><span style="font-family: "Times New Roman", serif;">的功能</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就要透過</span><span style="font-family: "Times New Roman", serif;">General setup —>Optimize for size ,</span><span style="font-family: "Times New Roman", serif;">選擇關閉 “</span><span style="font-family: "Times New Roman", serif;">Optimize for size “. </span><span style="font-family: "Times New Roman", serif;">而在</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">平台上</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">目前沒有“</span><span style="font-family: "Times New Roman", serif;">Kernel Function Graph Trace”</span><span style="font-family: "Times New Roman", serif;">的選項</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">所以就不受此限制</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">此外</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在</span><span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6.31 </span><span style="font-family: "Times New Roman", serif;">給</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">環境的組態中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">目前並不支援</span><span style="font-family: "Times New Roman", serif;">Dynamic Ftrace,</span><span style="font-family: "Times New Roman", serif;">所以像是</span><span style="font-family: "Times New Roman", serif;">set_ftrace_filter</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">set_ftrace_nontrace</span><span style="font-family: "Times New Roman", serif;">這類可以動態設定函式名稱過濾原則的機制</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在筆者環境中就無法支援</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我在說明時</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">會以</span><span style="font-family: "Times New Roman", serif;">x86</span><span style="font-family: "Times New Roman", serif;">版本來替代</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">後續支援與否請以</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">版本演進為主</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">在選單中進入</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —> Tracers —></span><span style="font-family: "Times New Roman", serif;">就可以選擇要開啟哪些</span><span style="font-family: "Times New Roman", serif;">Tracers</span><span style="font-family: "Times New Roman", serif;">功能</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以筆者手中針對</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">版本的</span><span style="font-family: "Times New Roman", serif;">Config</span><span style="font-family: "Times New Roman", serif;">內容如下 </span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">我是都勾選了</span><span style="font-family: "Times New Roman", serif;">…)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">-*- Kernel Function Tracer</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[*] Interrupts-off Latency Tracer</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[*] Scheduling Latency Tracer</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">-*- Trace process context switches</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[*] Trace boot initcalls</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[*] Trace likely/unlikely profiler</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[*] Profile all if conditionals</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[*] Trace likely/unlikely instances</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">[*] Trace max stack</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">最後確認</span><span style="font-family: "Times New Roman", serif;">Debug Filesystem</span><span style="font-family: "Times New Roman", serif;">是否有被勾選</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>-*- Debug Filesystem.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">退出選單</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">由於剛才已經勾選 “</span><span style="font-family: "Times New Roman", serif;">CONFIG_FUNCTION_TRACER” </span><span style="font-family: "Times New Roman", serif;">組態</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">可以參考檔案</span><span style="font-family: "Times New Roman", serif;">kernel/trace/Makefile</span><span style="font-family: "Times New Roman", serif;">的內容</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">設定 </span><span style="font-family: "Times New Roman", serif;">CONFIG_FUNCTION_TRACER</span><span style="font-family: "Times New Roman", serif;">後</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就會把</span><span style="font-family: "Times New Roman", serif;">KBUILD_CFLAGS</span><span style="font-family: "Times New Roman", serif;">加上 </span><span style="font-family: "Times New Roman", serif;">-pg ,</span><span style="font-family: "Times New Roman", serif;">每個核心函式中都會被置入</span><span style="font-family: "Times New Roman", serif;">mcount</span><span style="font-family: "Times New Roman", serif;">函式的呼叫</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>ifdef CONFIG_FUNCTION_TRACER</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>ORIG_CFLAGS := $(KBUILD_CFLAGS)</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>KBUILD_CFLAGS = $(subst -pg,,$(ORIG_CFLAGS))</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>…</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>endif</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Kernel</span><span style="font-family: "Times New Roman", serif;">內部有關除錯</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">或是</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">相關的檔案</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">會移除</span><span style="font-family: "Times New Roman", serif;">-pg</span><span style="font-family: "Times New Roman", serif;">的編譯參數</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">避免影響統計的結果</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">例如在</span><span style="font-family: "Times New Roman", serif;">kernel/Makefile</span><span style="font-family: "Times New Roman", serif;">檔案中</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>ifdef CONFIG_FUNCTION_TRACER</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># Do not trace debug files and internal ftrace files</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>CFLAGS_REMOVE_lockdep.o = -pg</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>CFLAGS_REMOVE_lockdep_proc.o = -pg</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>CFLAGS_REMOVE_mutex-debug.o = -pg</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;">…<span style="font-family: "Times New Roman", serif;"><strong>…………</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>endif</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">比較一下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">有打開 </span><span style="font-family: "Times New Roman", serif;">Function Tracer</span><span style="font-family: "Times New Roman", serif;">跟沒有打開</span><span style="font-family: "Times New Roman", serif;">Function Tracer</span><span style="font-family: "Times New Roman", serif;">的核心編譯結果如下所示</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">可以看到</span><span style="font-family: "Times New Roman", serif;">GCC</span><span style="font-family: "Times New Roman", serif;">編譯器</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">對編譯結果的影響</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 643px;"><colgroup><col width="263"></col><col width="363"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"><span style="font-family: "Times New Roman", serif;">沒有打開</span><span style="font-family: "Times New Roman", serif;">Ftracer</span><span style="font-family: "Times New Roman", serif;">的</span><span style="font-family: "Times New Roman", serif;">do_fork</span><span style="font-family: "Times New Roman", serif;">函式</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="363"><span style="font-family: "Times New Roman", serif;">打開</span><span style="font-family: "Times New Roman", serif;">Ftracer</span><span style="font-family: "Times New Roman", serif;">的</span><span style="font-family: "Times New Roman", serif;">do_fork</span><span style="font-family: "Times New Roman", serif;">函式</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">00001458 <do_fork>:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push {r4, r5, r6, r7, r8, r9, sl, lr}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">tst r0, #268435456 ; 0x10000000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub sp, sp, #32 ; 0x20</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r5, r0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r7, r1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r6, r2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov sl, r3</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bne 1688 <do_fork+0x230></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ands r4, r5, #33554432 ; 0x2000000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">moveq r9, #0 ; 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movne r9, #1 ; 0x1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bne 16c0 <do_fork+0x268></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ldr r3, [r6, #64]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">tst r3, #15 ; 0xf</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bne 149c <do_fork+0x44></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">tst r5, #8388608 ; 0x800000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">beq 1604 <do_fork+0x1ac></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r8, #0 ; 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ldr ip, [sp, #68]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r1, r7</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">str ip, [sp]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r2, r6</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="363"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">000018b0 <do_fork>:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov ip, sp</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">push {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr, pc}</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub fp, ip, #4 ; 0x4</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sub sp, sp, #52 ; 0x34</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov ip, lr</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>bl 0 <mcount></strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.word 0x00000040</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">tst r0, #268435456 ; 0x10000000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r7, r0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov sl, r1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r6, r2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">str r3, [fp, #-72]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bne 1c7c <do_fork+0x3cc></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ands r5, r7, #33554432 ; 0x2000000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">moveq r8, #0 ; 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">movne r8, #1 ; 0x1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r1, r8</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ldr r0, [pc, #1060] ; 1d20 <do_fork+0x470></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mov r2, #0 ; 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>bl 0 <ftrace_likely_update></strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">subs r1, r8, #0 ; 0x0</span></span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>DebugFS FileSystem</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">會使用虛擬的檔案系統</span><span style="font-family: "Times New Roman", serif;">debugfs</span><span style="font-family: "Times New Roman", serif;">做為設定檔與輸出結果的儲存位置</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我們可以先在根目錄產生 </span><span style="font-family: "Times New Roman", serif;">/debug</span><span style="font-family: "Times New Roman", serif;">檔案 </span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">然後</span><span style="font-family: "Times New Roman", serif;">mount debugfs</span><span style="font-family: "Times New Roman", serif;">到</span><span style="font-family: "Times New Roman", serif;">/debug</span><span style="font-family: "Times New Roman", serif;">目錄下 </span><span style="font-family: "Times New Roman", serif;">(Ftrace</span><span style="font-family: "Times New Roman", serif;">文件建議可以</span><span style="font-family: "Times New Roman", serif;">mount</span><span style="font-family: "Times New Roman", serif;">到</span><span style="font-family: "Times New Roman", serif;">/sys/kernel/debug</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># mkdir /debug</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># mount -t debugfs nodev /debug</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">之後進入</span><span style="font-family: "Times New Roman", serif;">/debug/tracing</span><span style="font-family: "Times New Roman", serif;">目錄下</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># cd /debug/tracing</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">查詢系統中支援哪些</span><span style="font-family: "Times New Roman", serif;">Tracer</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>$ cat available_tracers</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>function_graph function_duration function sched_switch nop</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">選擇 </span><span style="font-family: "Times New Roman", serif;">sched_switch</span><span style="font-family: "Times New Roman", serif;">作為目前運作的</span><span style="font-family: "Times New Roman", serif;">Tracer</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># echo sched_switch > current_tracer</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可以檢視目錄下的</span><span style="font-family: "Times New Roman", serif;">trace</span><span style="font-family: "Times New Roman", serif;">檔案</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">觀察</span><span style="font-family: "Times New Roman", serif;">sched_switch</span><span style="font-family: "Times New Roman", serif;">輸出的結果</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># cat trace</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># tracer: sched_switch</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>#</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># TASK-PID CPU# TIMESTAMP FUNCTION</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># | | | | |</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong><idle>-0 [000] 745.934676: 0:140:R ==> [000] 2892:120:R</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>gnome-terminal-2892 [000] 745.934770: 2892:120:S ==> [000] 0:140:R</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong><idle>-0 [000] 745.934861: 0:140:R ==> [000] 2892:120:R</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>gnome-terminal-2892 [000] 745.934937: 2892:120:S ==> [000] 0:140:R</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>bash-5175 [001] 745.934960: 5175:120:S + [000] 2892:120:S</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-5175 [001] 745.935149: 5175:120:S + [000] 2892:120:S</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">暫停</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">的運作</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># echo nop > current_tracer</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">上述步驟</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">為透過</span><span style="font-family: "Times New Roman", serif;">debugfs</span><span style="font-family: "Times New Roman", serif;">操作</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">的基本行為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">接下來讓我們初步認識</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">相關的控制檔案</span><span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>介紹</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Ftrace </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>目錄</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>tracing</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>下的檔案</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">我們以</span><span style="font-family: "Times New Roman", serif;">Android ARM</span><span style="font-family: "Times New Roman", serif;">平台搭配</span><span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6.31</span><span style="font-family: "Times New Roman", serif;">為例子</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">首先建立 </span><span style="font-family: "Times New Roman", serif;">/data/debug</span><span style="font-family: "Times New Roman", serif;">目錄</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">並且把 </span><span style="font-family: "Times New Roman", serif;">debugfs </span><span style="font-family: "Times New Roman", serif;">虛擬檔案系統載入</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"># mkdir /data/debug</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"># mount -t debugfs nodev /data/debug</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"># cd /data/debug</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">瀏覽目錄下的內容</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"># ls</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">sched_features</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">mmc0</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">tracing</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">bdi</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">#</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">進入目錄</span><span style="font-family: "Times New Roman", serif;">tracing</span><span style="font-family: "Times New Roman", serif;">後</span><span style="font-family: "Times New Roman", serif;">,ls</span><span style="font-family: "Times New Roman", serif;">瀏覽該目錄的結果</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"># cd /data/debug</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"># ls -l</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-r–r–r– root root 0 1970-01-01 00:00 stack_trace</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 stack_max_size</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">drwxr-xr-x root root 1970-01-01 00:00 events</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 set_event</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-r–r–r– root root 0 1970-01-01 00:00 available_events</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-r–r–r– root root 0 1970-01-01 00:00 printk_formats</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">drwxr-xr-x root root 1970-01-01 00:00 per_cpu</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">drwxr-xr-x root root 1970-01-01 00:00 options</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-r–r–r– root root 0 1970-01-01 00:00 saved_cmdlines</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">–w–w—- root root 0 1970-01-01 00:00 trace_marker</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 buffer_size_kb</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-r–r–r– root root 0 1970-01-01 00:00 trace_pipe</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-r–r–r– root root 0 1970-01-01 00:00 README</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 tracing_thresh</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 tracing_max_latency</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 current_tracer</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-r–r–r– root root 0 1970-01-01 00:00 available_tracers</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 trace</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 tracing_cpumask</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 trace_options</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 tracing_enabled</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 tracing_on</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 function_profile_enabled</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">drwxr-xr-x root root 1970-01-01 00:00 trace_stat</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">-rw-r–r– root root 0 1970-01-01 00:00 set_ftrace_pid</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">接下來</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">筆者以這目錄下的檔案</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">挑選認為應該說明的部份</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如下所示</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 646px;"><colgroup><col width="103"></col><col width="526"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">檔案名稱</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">說明</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">current_tracer</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">用來顯示目前被設定的</span><span style="font-family: "Times New Roman", serif;">Tracer.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">如果沒有任何被設定的</span><span style="font-family: "Times New Roman", serif;">Tracer </span><span style="font-family: "Times New Roman", serif;">就會返回</span><span style="font-family: "Times New Roman", serif;">nop</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># cat current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nop</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">以 </span><span style="font-family: "Times New Roman", serif;">sched_switch</span><span style="font-family: "Times New Roman", serif;">設定到</span><span style="font-family: "Times New Roman", serif;">current_tracer</span><span style="font-family: "Times New Roman", serif;">來示範這檔案的功能</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo > /data/debug/tracing/trace <span style="color: red;"><strong>=></strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>清空</strong></span><span style="font-family: "Times New Roman", serif;"><strong>trace</strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>內容</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo sched_switch > /data/debug/tracing/current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 1 > /data/debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># sleep 1</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 0 > /data/debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat /data/debug/tracing/trace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: sched_switch</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-9560 [000] 52138.209612: 9560:120:R ==> [000] 9538:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:1-9538 [000] 52138.209903: 9538:120:S ==> [000] 9558:120:R in.telnetd</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-9558 [000] 52138.211017: 9558:120:S ==> [000] 9560:120:R bash</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-9560 [000] 52138.211412: 9560:120:S + [000] 9560:120:S bash</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-9560 [000] 52138.211613: 9560:120:R + [000] 9538:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-9560 [000] 52138.211820: 9560:120:R ==> [000] 9538:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:1-9538 [000] 52138.211990: 9538:120:R + [000] 9558:120:R in.telnetd</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:1-9538 [000] 52138.212148: 9538:120:S ==> [000] 9558:120:R in.telnetd</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-9558 [000] 52138.212953: 9558:120:S ==> [000] 9560:120:R bash</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-9560 [000] 52138.213221: 9560:120:S ==> [000] 0:120:R <idle></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 52138.414815: 0:120:R + [000] 9538:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 52138.414976: 0:120:R ==> [000] 9538:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:1-9538 [000] 52138.415243: 9538:120:S ==> [000] 0:120:R <idle></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 52138.417111: 0:120:R + [000] 9538:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 52138.417312: 0:120:R ==> [000] 9538:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:1-9538 [000] 52138.417541: 9538:120:S ==> [000] 0:120:R <idle></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 52138.448254: 0:120:R + [000] 1811:120:R pcscd</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 52138.448547: 0:120:R ==> [000] 1811:120:R pcscd</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">pcscd-1811 [000] 52138.450170: 1811:120:S ==> [000] 0:120:R <idle></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 52138.540657: 0:120:R + [000] 1892:139:R gam_server</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">available_tracers</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">列出目前</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">中在編譯時有被啟用的</span><span style="font-family: "Times New Roman", serif;">Tracer. </span><span style="font-family: "Times New Roman", serif;">我們只要把這些對應的名字設定到</span><span style="font-family: "Times New Roman", serif;">current_tracer</span><span style="font-family: "Times New Roman", serif;">中就可以啟用對應的</span><span style="font-family: "Times New Roman", serif;">Tracer. </span><span style="font-family: "Times New Roman", serif;">如下所示為筆者環境中所支持的</span><span style="font-family: "Times New Roman", serif;">Tracer.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># cat available_tracers</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">blk kmemtrace branch wakeup_rt wakeup irqsoff function sched_switch initcall nop</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">tracing_enabled</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">用以控制</span><span style="font-family: "Times New Roman", serif;">Tracer</span><span style="font-family: "Times New Roman", serif;">的啟動或是停止</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">當為</span><span style="font-family: "Times New Roman", serif;">1</span><span style="font-family: "Times New Roman", serif;">時表示</span><span style="font-family: "Times New Roman", serif;">Tracer</span><span style="font-family: "Times New Roman", serif;">啟動</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">反之</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">為</span><span style="font-family: "Times New Roman", serif;">0</span><span style="font-family: "Times New Roman", serif;">就是停止</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如下所示</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">啟動 </span><span style="font-family: "Times New Roman", serif;">Tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>#echo 1 > /data/debug/tracing/tracing_enabled</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">暫停 </span><span style="font-family: "Times New Roman", serif;">Tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>#echo 0 > /data/debug/tracing/tracing_enabled</strong></span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">trace</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">用以把</span><span style="font-family: "Times New Roman", serif;">Tracer</span><span style="font-family: "Times New Roman", serif;">的結果呈現出人可閱讀的格式</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#more /data/debug/tracing/trace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">清空</span><span style="font-family: "Times New Roman", serif;">Tracer</span><span style="font-family: "Times New Roman", serif;">結果內容</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo > /data/debug/tracing/trace</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">trace_pipe</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">支援</span><span style="font-family: "Times New Roman", serif;">以</span><span style="font-family: "Times New Roman", serif;">pipe</span><span style="font-family: "Times New Roman", serif;">的機制讀取跟</span><span style="font-family: "Times New Roman", serif;">trace</span><span style="font-family: "Times New Roman", serif;">檔案一樣的內容</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">並</span><span style="font-family: "Times New Roman", serif;">以</span><span style="font-family: "Times New Roman", serif;">Block</span><span style="font-family: "Times New Roman", serif;">的機制讀取</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">直到有資料進來後</span><span style="font-family: "Times New Roman", serif;">才</span><span style="font-family: "Times New Roman", serif;">會返回</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">每次資料讀取後</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">下一次讀取</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就會讀取到新的資料</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">適合用來循序讀取</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">把</span><span style="font-family: "Times New Roman", serif;">Trace</span><span style="font-family: "Times New Roman", serif;">內容</span><span style="font-family: "Times New Roman", serif;">依序讀</span><span style="font-family: "Times New Roman", serif;">出來</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">如果希望每次都讀取到完整</span><span style="font-family: "Times New Roman", serif;">的</span><span style="font-family: "Times New Roman", serif;">trace buffer</span><span style="font-family: "Times New Roman", serif;">內容</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就從</span><span style="font-family: "Times New Roman", serif;">trace</span><span style="font-family: "Times New Roman", serif;">檔案中讀取</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">反之</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如果是每次都要讀到沒讀取到的資料</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就可以從</span><span style="font-family: "Times New Roman", serif;">trace_pipe</span><span style="font-family: "Times New Roman", serif;">中讀取</span><span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">trace_options</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">可以用來控制</span><span style="font-family: "Times New Roman", serif;">trace</span><span style="font-family: "Times New Roman", serif;">要顯示的資料內容</span><span style="font-family: "Times New Roman", serif;">. (</span><span style="font-family: "Times New Roman", serif;">ㄟ 也必須要該</span><span style="font-family: "Times New Roman", serif;">Plug-in Tracer</span><span style="font-family: "Times New Roman", serif;">有支援對應的</span><span style="font-family: "Times New Roman", serif;">Options).</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat trace_options</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">print-parent</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nosym-offset</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nosym-addr</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">noverbose</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">noraw</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nohex</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nobin</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">noblock</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nostacktrace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nosched-tree</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">trace_printk</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">noftrace_preempt</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nobranch</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">annotate</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nouserstacktrace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nosym-userobj</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">noprintk-msg-only</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">context-info</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">nolatency-format</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">noglobal-clock</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sleep-time</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">graph-time</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">控制方式為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">把</span><span style="font-family: "Times New Roman", serif;">Option</span><span style="font-family: "Times New Roman", serif;">內容選擇加上 </span><span style="font-family: "Times New Roman", serif;">no (</span><span style="font-family: "Times New Roman", serif;">關閉</span><span style="font-family: "Times New Roman", serif;">)</span><span style="font-family: "Times New Roman", serif;">或是移除</span><span style="font-family: "Times New Roman", serif;">no(</span><span style="font-family: "Times New Roman", serif;">開啟</span><span style="font-family: "Times New Roman", serif;">),</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">例如</span><span style="font-family: "Times New Roman", serif;">:</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">關閉</span><span style="font-family: "Times New Roman", serif;">print-parent</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># echo noprint-parent > /data/debug/tracing/trace_options</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">重新 </span><span style="font-family: "Times New Roman", serif;">cat trace_options</span><span style="font-family: "Times New Roman", serif;">就會看到</span><span style="font-family: "Times New Roman", serif;">print-parent</span><span style="font-family: "Times New Roman", serif;">變成</span><span style="font-family: "Times New Roman", serif;">noprint-parent</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">反之</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">原本設定為</span><span style="font-family: "Times New Roman", serif;">nosym-addr,</span><span style="font-family: "Times New Roman", serif;">透過</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>#echo sym-addr > /data/debug/tracing/trace_options</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">重新 </span><span style="font-family: "Times New Roman", serif;">cat trace_options</span><span style="font-family: "Times New Roman", serif;">就會看到</span><span style="font-family: "Times New Roman", serif;">nosym-addr </span><span style="font-family: "Times New Roman", serif;">變成 </span><span style="font-family: "Times New Roman", serif;">sym-addr</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">tracing_max_latency</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">用以顯示剛才的</span><span style="font-family: "Times New Roman", serif;">Tracer</span><span style="font-family: "Times New Roman", serif;">進行</span><span style="font-family: "Times New Roman", serif;">Latency</span><span style="font-family: "Times New Roman", serif;">統計時</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">例如</span><span style="font-family: "Times New Roman", serif;">: irqsoff </span><span style="font-family: "Times New Roman", serif;">或是 </span><span style="font-family: "Times New Roman", serif;">wakeup…etc),</span><span style="font-family: "Times New Roman", serif;">最大的 </span><span style="font-family: "Times New Roman", serif;">Latency</span><span style="font-family: "Times New Roman", serif;">數值為何</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">單位為 </span><span style="font-family: "Times New Roman", serif;">us),</span><span style="font-family: "Times New Roman", serif;">以提供核心設計者</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">找出系統中比較缺乏效率的部份</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">加以改善</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"># echo irqsoff > </span><span style="color: red;"><strong>/data/debug/tracing/</strong></span><span style="color: red;">current_tracer</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"># echo 1 > </span><span style="color: red;"><strong>/data/debug/tracing/</strong></span><span style="color: red;">tracing_enabled</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;">…<span style="font-family: "Times New Roman", serif;">.do somehting….sleep….</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"># echo 0 > </span><span style="color: red;"><strong>/data/debug/tracing/</strong></span><span style="color: red;">tracing_enabled</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"># more tracing_max_latency</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;">7367</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"># more </span><span style="color: red;"><strong>/data/debug/tracing/</strong></span><span style="color: red;">trace</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># tracer: irqsoff</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>#</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># irqsoff latency trace v1.1.5 on 2.6.38.6</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># ——————————————————————–</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># latency: 7367 us, #58/58, CPU#0 | (M:desktop VP:0, KP:0, SP:0 HP:0 #P:1)</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># —————–</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># | task: bash-1905 (uid:0 nice:0 policy:0 rt_prio:0)</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># —————–</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># => started at: apic_timer_interrupt</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># => ended at: call_on_stack</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>#</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>#</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># _——=> CPU#</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># / _—–=> irqs-off</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># | / _—-=> need-resched</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># || / _—=> hardirq/softirq</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># ||| / _–=> preempt-depth</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># |||| /_–=> lock-depth</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># |||||/ delay</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># cmd pid |||||| time | caller</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># \ / |||||| \ | /</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><strong>…etc</strong></span></span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">buffer_size_kb</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">用來設定每個處理器要用多少記憶體空間當做</span><span style="font-family: "Times New Roman", serif;">Tracer Buffer (</span><span style="font-family: "Times New Roman", serif;">單位為</span><span style="font-family: "Times New Roman", serif;">kbytes)(</span><span style="font-family: "Times New Roman", serif;">一般而言一個</span><span style="font-family: "Times New Roman", serif;">Page</span><span style="font-family: "Times New Roman", serif;">單位為</span><span style="font-family: "Times New Roman", serif;">4kbytes)(</span><span style="font-family: "Times New Roman", serif;">每個處理器都會依據此值配置一樣大的空間</span><span style="font-family: "Times New Roman", serif;">),</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">例如</span><span style="font-family: "Times New Roman", serif;">:</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat buffer_size_kb</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1408</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">就表示在筆者環境中為每個處理器用 </span><span style="font-family: "Times New Roman", serif;">1.408MB</span><span style="font-family: "Times New Roman", serif;">當做</span><span style="font-family: "Times New Roman", serif;">Tracer Buffer.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">這個值只有在</span><span style="font-family: "Times New Roman", serif;">current_tracer</span><span style="font-family: "Times New Roman", serif;">內容為 “</span><span style="font-family: "Times New Roman", serif;">nop”</span><span style="font-family: "Times New Roman", serif;">時才可以修改</span><span style="font-family: "Times New Roman", serif;">. (</span><span style="font-family: "Times New Roman", serif;">也就是說要沒有啟用任何</span><span style="font-family: "Times New Roman", serif;">Tracer Plug-in</span><span style="font-family: "Times New Roman", serif;">才可以修改這個值</span><span style="font-family: "Times New Roman", serif;">)</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">tracing_cpumask</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">用來設定</span><span style="font-family: "Times New Roman", serif;">Tracer</span><span style="font-family: "Times New Roman", serif;">要在哪個處理器上蒐集資訊</span><span style="font-family: "Times New Roman", serif;">. </span><span style="font-family: "Times New Roman", serif;">顯示的為字串</span><span style="font-family: "Times New Roman", serif;">16</span><span style="font-family: "Times New Roman", serif;">進位的字串</span><span style="font-family: "Times New Roman", serif;">.</span><span style="font-family: "Times New Roman", serif;">在筆者單核</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">的環境中執行如下</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat tracing_cpumask</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">set_ftrace_filter</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">用在動態</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">的組態下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">程式碼在編譯過程中被</span><span style="font-family: "Times New Roman", serif;">gcc -pg</span><span style="font-family: "Times New Roman", serif;">置入呼叫</span><span style="font-family: "Times New Roman", serif;">mcount</span><span style="font-family: "Times New Roman", serif;">函式的行為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在</span><span style="font-family: "Times New Roman", serif;">支援</span><span style="font-family: "Times New Roman", serif;">動態</span><span style="font-family: "Times New Roman", serif;">Ftrace (Dynamic Ftrace)</span><span style="font-family: "Times New Roman", serif;">的環境中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">只有在透過這檔案設定的函式</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">才會被納入</span><span style="font-family: "Times New Roman", serif;">Function Trace</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定</span><span style="font-family: "Times New Roman", serif;">Trace Functon</span><span style="font-family: "Times New Roman", serif;">開頭為 </span><span style="font-family: "Times New Roman", serif;">account</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">run</span><span style="font-family: "Times New Roman", serif;">的函式呼叫行為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如下指令所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo > /debug/tracing/trace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo ‘account*’ ‘run*’ > /debug/tracing/set_ftrace_filter</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo function > /debug/tracing/current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#sleep 1</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat /debug/tracing/trace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: function</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2602.286489: account_process_tick <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2602.286501: account_system_time <-account_process_tick</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2602.286510: run_local_timers <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2602.286565: run_posix_cpu_timers <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2602.286605: run_timer_softirq <-__do_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 2602.287494: account_process_tick <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 2602.287503: account_system_time <-account_process_tick</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 2602.287509: run_local_timers <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 2602.287565: run_posix_cpu_timers <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 2602.287605: run_timer_softirq <-__do_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">在筆者的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6.31 ARM</span><span style="font-family: "Times New Roman", serif;">的設置中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">目前並沒有支援 </span><span style="font-family: "Times New Roman", serif;">HAVE_DYNAMIC_FTRACE,</span><span style="font-family: "Times New Roman", serif;">也就是說在</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">版本中這個檔案屬性會無法使用</span><span style="font-family: "Times New Roman", serif;">. (</span><span style="font-family: "Times New Roman", serif;">還請以各位手中的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">版本為主</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">看是否有新的更新</span><span style="font-family: "Times New Roman", serif;">.)</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">set_ftrace_notrace</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">跟</span><span style="font-family: "Times New Roman", serif;">set_ftrace_filter</span><span style="font-family: "Times New Roman", serif;">相反</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在動態</span><span style="font-family: "Times New Roman", serif;">Ftrace(Dynamic Ftrace)</span><span style="font-family: "Times New Roman", serif;">的組態下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">那設定到這檔案中的函式名稱</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">都會被取消呼叫</span><span style="font-family: "Times New Roman", serif;">mcount</span><span style="font-family: "Times New Roman", serif;">的動作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">不納入</span><span style="font-family: "Times New Roman", serif;">Function Trace</span><span style="font-family: "Times New Roman", serif;">的機制中</span><span style="font-family: "Times New Roman", serif;">. </span><span style="font-family: "Times New Roman", serif;">如果同一個函式同時被設定到 </span><span style="font-family: "Times New Roman", serif;">set_ftrace_filter </span><span style="font-family: "Times New Roman", serif;">與 </span><span style="font-family: "Times New Roman", serif;">set_ftrace_notrace,</span><span style="font-family: "Times New Roman", serif;">則該函式將會以 </span><span style="font-family: "Times New Roman", serif;">set_ftrace_notrace</span><span style="font-family: "Times New Roman", serif;">為主</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">將不納入</span><span style="font-family: "Times New Roman", serif;">Trace</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定不要</span><span style="font-family: "Times New Roman", serif;">Trace</span><span style="font-family: "Times New Roman", serif;">有包含</span><span style="font-family: "Times New Roman", serif;">cpu</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">align</span><span style="font-family: "Times New Roman", serif;">字元的函式名稱</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如下指令所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo ‘*cpu*’ ‘*align*’ > /debug/tracing/set_ftrace_notrace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo function > /debug/tracing/current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#sleep 1</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat /debug/tracing/trace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630911: calc_global_load <-do_timer</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630921: update_process_times <-tick_periodic</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630929: account_process_tick <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630937: account_system_time <-account_process_tick</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630945: run_local_timers <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630953: hrtimer_run_queues <-run_local_timers</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630967: __current_kernel_time <-hrtimer_run_queues</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630974: __get_wall_to_monotonic <-hrtimer_run_queues</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630984: _raw_spin_lock <-hrtimer_run_queues</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.630995: raise_softirq <-run_local_timers</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.631006: rcu_check_callbacks <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.631014: rcu_bh_qs <-rcu_check_callbacks</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1951 [000] 2331.631022: __rcu_pending <-rcu_check_callbacks</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">在筆者的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6.31 ARM</span><span style="font-family: "Times New Roman", serif;">的設置中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">目前並沒有支援 </span><span style="font-family: "Times New Roman", serif;">HAVE_DYNAMIC_FTRACE,</span><span style="font-family: "Times New Roman", serif;">也就是說在</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">版本中這個檔案屬性會無法使用</span><span style="font-family: "Times New Roman", serif;">. (</span><span style="font-family: "Times New Roman", serif;">還請以各位手中的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">版本為主</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">看是否有新的更新</span><span style="font-family: "Times New Roman", serif;">.)</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">set_ftrace_pid</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">設定</span><span style="font-family: "Times New Roman", serif;">Function tracer</span><span style="font-family: "Times New Roman", serif;">只針對特定的</span><span style="font-family: "Times New Roman", serif;">PID</span><span style="font-family: "Times New Roman", serif;">進行蒐集</span><span style="font-family: "Times New Roman", serif;">. (</span><span style="font-family: "Times New Roman", serif;">如果不設定這個值</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">而是對全系統蒐集</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">很有可能會讓系統</span><span style="font-family: "Times New Roman", serif;">Hang</span><span style="font-family: "Times New Roman", serif;">住</span><span style="font-family: "Times New Roman", serif;">=></span><span style="font-family: "Times New Roman", serif;">在我的</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">環境中不設定</span><span style="font-family: "Times New Roman", serif;">PID</span><span style="font-family: "Times New Roman", serif;">縮小範圍</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就會</span><span style="font-family: "Times New Roman", serif;">Hang</span><span style="font-family: "Times New Roman", serif;">住</span><span style="font-family: "Times New Roman", serif;">…@_@)</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">操作範例如下</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat /debug/tracing/set_ftrace_pid</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">no pid</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#ps <span style="color: red;"><strong>=></strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>找一個要</strong></span><span style="font-family: "Times New Roman", serif;"><strong>Trace</strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>的</strong></span><span style="font-family: "Times New Roman", serif;"><strong>Process ID</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">USER PID PPID VSIZE RSS WCHAN PC NAME</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">system 65 31 152436 25296 ffffffff afd0db4c S system_server</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">app_23 128 31 111664 20728 ffffffff afd0eb08 S com.android.launcher</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># echo 65 > /data/debug/tracing/set_ftrace_pid</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># echo function > /data/debug/tracing/current_tracer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong># echo 1 > /data/debug/tracing/tracing_enabled</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;">…<span style="font-family: "Times New Roman", serif;"><strong>.do something….</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>#cat /data/debug/tracing/trace</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">.</span><span style="font-family: "Times New Roman", serif;">此時 </span><span style="font-family: "Times New Roman", serif;">trace</span><span style="font-family: "Times New Roman", serif;">中就只會顯示該 </span><span style="font-family: "Times New Roman", serif;">PID</span><span style="font-family: "Times New Roman", serif;">的</span><span style="font-family: "Times New Roman", serif;">tracing</span><span style="font-family: "Times New Roman", serif;">結果</span><span style="font-family: "Times New Roman", serif;">…</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">available_filter_functions</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"><span style="font-family: "Times New Roman", serif;">這個檔案會列出目前所有可以供</span><span style="font-family: "Times New Roman", serif;">“set_ftrace_filter” </span><span style="font-family: "Times New Roman", serif;">或 </span><span style="font-family: "Times New Roman", serif;">“set_ftrace_notrace”</span><span style="font-family: "Times New Roman", serif;">用來設定過濾條件的函式名稱</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">例如</span><span style="font-family: "Times New Roman", serif;">:</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># more /debug/tracing/available_filter_functions</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">_stext</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">do_one_initcall</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">run_init_process</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">init_post</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">name_to_dev_t</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">match_dev_by_uuid</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">thread_saved_pc</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">get_wchan</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">prepare_to_copy</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">release_thread</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">copy_thread</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">start_thread</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">__show_regs</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cpu_idle</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">setup_sigcontext</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">align_sigframe</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">signal_fault</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sys_sigaltstack</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">restore_sigcontext</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sys_sigaction</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sys_rt_sigreturn</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">do_notify_resume</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">.etc</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="526"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>介紹</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Ftrace</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>每個模組</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">的設計概念為提供</span><span style="font-family: "Times New Roman", serif;">Plug-in Framework</span><span style="font-family: "Times New Roman", serif;">的機制</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">隨著核心模組的演進</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如果需要針對新的核心模組進行效能上的統計分析時</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就可以透過</span><span style="font-family: "Times New Roman", serif;">Plug-in</span><span style="font-family: "Times New Roman", serif;">的方式</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">撰寫新的</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">模組達成新的</span><span style="font-family: "Times New Roman", serif;">tracer</span><span style="font-family: "Times New Roman", serif;">目的</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">作為一個可延展性的</span><span style="font-family: "Times New Roman", serif;">Tracer </span><span style="font-family: "Times New Roman", serif;">架構</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">本段落會介紹</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">主要支援的</span><span style="font-family: "Times New Roman", serif;">Tracer</span><span style="font-family: "Times New Roman", serif;">模組</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">這些模組的數量或是功能</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">都有可能隨著</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">演進而有所改動 </span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">例如</span><span style="font-family: "Times New Roman", serif;">:Kernel 2.6.39</span><span style="font-family: "Times New Roman", serif;">移除 </span><span style="font-family: "Times New Roman", serif;">Kernel Lock),</span><span style="font-family: "Times New Roman", serif;">版本的更迭</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">都請以最新的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel Source Code</span><span style="font-family: "Times New Roman", serif;">為主要依據</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 649px;"><colgroup><col width="107"></col><col width="524"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">名稱</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">說明</span></div>
</td></tr>
<tr valign="TOP"><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;"><strong>Function tracer</strong></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Kernel Function Tracer</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">用以顯示</span><span style="font-family: "Times New Roman", serif;">,Function</span><span style="font-family: "Times New Roman", serif;">呼叫的流程與順序</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">操作範例如下所示</span><span style="font-family: "Times New Roman", serif;">:</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1855 > /debug/tracing/set_ftrace_pid</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>=></strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>選擇</strong></span><span style="font-family: "Times New Roman", serif;"><strong>vsftpd </strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>的</strong></span><span style="font-family: "Times New Roman", serif;"><strong>PID (=1855)</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo function > /debug/tracing/current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>=></strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>選擇</strong></span><span style="font-family: "Times New Roman", serif;"><strong>Function Tracer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>=></strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>之後透過另一台電腦經由</strong></span><span style="font-family: "Times New Roman", serif;"><strong>FTP</strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>連線到這主機來</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>就可以記錄到這</strong></span><span style="font-family: "Times New Roman", serif;"><strong>Daemon Function</strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>操作的行為</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat /debug/tracing/trace > /trace.txt</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo nop > /debug/tracing/current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;"><strong>=></strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>移除</strong></span><span style="font-family: "Times New Roman", serif;"><strong>Tracer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">再來看 </span><span style="font-family: "Times New Roman", serif;">trace.txt</span><span style="font-family: "Times New Roman", serif;">中結果如下</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: function</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754213: irq_exit <-smp_apic_timer_interrupt</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754222: do_softirq <-irq_exit</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754229: call_on_stack <-do_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754235: __do_softirq <-call_on_stack</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754241: __local_bh_disable <-__do_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754279: run_timer_softirq <-__do_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754302: hrtimer_run_pending <-run_timer_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754324: _raw_spin_lock_irq <-run_timer_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754347: rcu_bh_qs <-__do_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754378: rcu_process_callbacks <-__do_softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754400: __rcu_process_callbacks <-rcu_process_callbacks</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754422: force_quiescent_state <-__rcu_process_callbacks</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1964 [000] 272.754444: rcu_gp_in_progress <-force_quiescent_state</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">…</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可以看到在</span><span style="font-family: "Times New Roman", serif;">vsftpd</span><span style="font-family: "Times New Roman", serif;">對應處理</span><span style="font-family: "Times New Roman", serif;">Client</span><span style="font-family: "Times New Roman", serif;">需求的行程運作時</span><span style="font-family: "Times New Roman", serif;">,Linux Kernel</span><span style="font-family: "Times New Roman", serif;">這所對應調用的函式行為與時間值</span><span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Dynamic selection of functions</strong></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>enable/disable ftrace tracepoints dynamically</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">由於對全部</span><span style="font-family: "Times New Roman", serif;">Function Tracing</span><span style="font-family: "Times New Roman", serif;">的成本很高</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以筆者所用的</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">環境而言</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">幾乎會導致系統無法正常的反應</span><span style="font-family: "Times New Roman", serif;">(mmm,</span><span style="font-family: "Times New Roman", serif;">如果你是用</span><span style="font-family: "Times New Roman", serif;">ARM Cortex A</span><span style="font-family: "Times New Roman", serif;">系列的處理器</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">應該就會很順了</span><span style="font-family: "Times New Roman", serif;">…),Ftrace</span><span style="font-family: "Times New Roman", serif;">也提供了動態選擇</span><span style="font-family: "Times New Roman", serif;">Function(Dynamic selection of functions) </span><span style="font-family: "Times New Roman", serif;">進行</span><span style="font-family: "Times New Roman", serif;">Tracing</span><span style="font-family: "Times New Roman", serif;">的機制</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以筆者所驗證的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6.31</span><span style="font-family: "Times New Roman", serif;">而言</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">目前在</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">平台</span><span style="font-family: "Times New Roman", serif;">尚未</span><span style="font-family: "Times New Roman", serif;">支援這機制</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">而</span><span style="font-family: "Times New Roman", serif;">X86</span><span style="font-family: "Times New Roman", serif;">平台則可以支援</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">使用範例如下的寫法</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">選擇只追蹤函式名稱包含有 </span><span style="font-family: "Times New Roman", serif;">spin</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">process</span><span style="font-family: "Times New Roman", serif;">字串的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel Function</span><span style="font-family: "Times New Roman", serif;">呼叫</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo ‘*spin*’ ‘*process*’ > /debug/tracing/set_ftrace_filter</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">執行結果如下所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: function</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651690: _raw_spin_lock_bh <-lock_sock_nested</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651739: _raw_spin_lock_bh <-release_sock</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651760: _raw_spin_unlock_bh <-release_sock</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651780: _raw_spin_lock_bh <-lock_sock_nested</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651800: _raw_spin_lock_bh <-release_sock</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651819: _raw_spin_unlock_bh <-release_sock</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651840: _raw_spin_lock <-fd_install</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651871: _raw_spin_lock_irq <-sigprocmask</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651924: _raw_spin_lock_irq <-sigprocmask</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.651974: _raw_spin_lock <-tick_periodic</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.652009: update_process_times <-tick_periodic</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.652017: account_process_tick <-update_process</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.652034: _raw_spin_lock <-hrtimer_run_queues</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.652082: _raw_spin_lock <-scheduler_tick</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.652164: _raw_spin_lock_irq <-run_timer_softir</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">q</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.652241: copy_process <-do_fork</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5064.652278: _raw_spin_lock <-cache_alloc_refill</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">..</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">就只會看到有包含 </span><span style="font-family: "Times New Roman", serif;">spin</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">process</span><span style="font-family: "Times New Roman", serif;">字串的函式呼叫</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">接下來</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如果要把有包含 </span><span style="font-family: "Times New Roman", serif;">raw </span><span style="font-family: "Times New Roman", serif;">與 </span><span style="font-family: "Times New Roman", serif;">times</span><span style="font-family: "Times New Roman", serif;">字元的函式過濾掉</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">可透過如下設定</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo ‘*raw*’ ‘*times*’ > /debug/tracing/set_ftrace_notrace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">執行結果如下所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: function</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.419859: tcp_rcv_state_process <-tcp_v4_do_rcv</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.419996: account_process_tick <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.420520: tcp_child_process <-tcp_v4_do_rcv</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.420542: tcp_rcv_state_process <-tcp_child_process</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.420913: wake_up_process <-wake_up_worker</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.421737: account_process_tick <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5220.422045: account_process_tick <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5220.422358: copy_process <-do_fork</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-1855 [000] 5220.422953: account_process_tick <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.423830: tcp_rcv_state_process <-tcp_v4_do_rcv</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.423903: kick_process <-signal_wake_up</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.423961: account_process_tick <-update_process_times</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vsftpd-2099 [000] 5220.424257: kick_process <-signal_wake_up</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">..</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可以看到最後的結果</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就是會包含有 </span><span style="font-family: "Times New Roman", serif;">spin</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">process</span><span style="font-family: "Times New Roman", serif;">字串的函式呼叫</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">並且把其中有包括 </span><span style="font-family: "Times New Roman", serif;">raw</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">times</span><span style="font-family: "Times New Roman", serif;">字串的函式呼叫過濾掉</span><span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Function graph tracer</strong></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Kernel Function Tracer —>Kernel Function Graph Tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">以筆者所驗證的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6.31</span><span style="font-family: "Times New Roman", serif;">而言</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">目前在</span><span style="font-family: "Times New Roman", serif;">ARM</span><span style="font-family: "Times New Roman", serif;">平台</span><span style="font-family: "Times New Roman", serif;">尚未</span><span style="font-family: "Times New Roman", serif;">支援這機制</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">而</span><span style="font-family: "Times New Roman", serif;">X86</span><span style="font-family: "Times New Roman", serif;">平台則可以支援</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">操作範例如下所示</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo ‘*’ > /debug/tracing/set_ftrace_filter</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;">=></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;">恢復對所有函式的</span><span style="font-family: "Times New Roman", serif;">Tracing</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo function_graph > /debug/tracing/current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: red;">=></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;">讓 </span><span style="font-family: "Times New Roman", serif;">FTP Client</span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;">連進來</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 0 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">執行結果如下所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: function_graph</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TIME CPU DURATION FUNCTION CALLS</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 7.525 us | } /* idle_cpu */</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 36.032 us | } /* irq_enter */</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | tick_handle_periodic() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | tick_periodic() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | do_timer() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 16.017 us | update_wall_time();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.749 us | calc_global_load();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 43.684 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | account_process_tick() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.852 us | account_system_time();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 20.041 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | run_local_timers() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | hrtimer_run_queues() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.243 us | __current_kernel_time();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.183 us | __get_wall_to_monotonic();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 35.781 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 9.591 us | raise_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 65.198 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | rcu_check_callbacks() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.357 us | idle_cpu();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | __rcu_pending() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.199 us | rcu_gp_in_progress();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.218 us | cpu_has_callbacks_ready_to_invoke();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.265 us | cpu_needs_another_gp();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.175 us | rcu_gp_in_progress();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 59.513 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.867 us | raise_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 98.833 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.292 us | printk_tick();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | scheduler_tick() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 11.142 us | ktime_get();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 7.172 us | update_rq_clock();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | sched_avg_update() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.353 us | sched_avg_period();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 19.685 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | task_tick_fair() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.826 us | update_curr();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) | sched_slice() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) 6.851 us | calc_delta_mine();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) + 20.522 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">原本結果顯示的是時間差</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">也可以透過 </span><span style="font-family: "Times New Roman", serif;">trace_options</span><span style="font-family: "Times New Roman", serif;">選擇顯示絕對時間值</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo funcgraph-abstime >/debug/tracing/trace_options</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">執行結果如下所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: function_graph</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TIME CPU DURATION FUNCTION CALLS</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.132197 | 0) ! 201.630 us | } /* __do_softirq */</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.132218 | 0) ! 265.733 us | } /* do_softirq */</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.132229 | 0) ! 297.422 us | } /* irq_exit */</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">——————————————</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) vsftpd-2125 => <…>-1855</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">——————————————</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.132798 | 0) + 50.964 us | irq_enter();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.132908 | 0) + 25.462 us | raise_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.133053 | 0) | irq_exit() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.133076 | 0) | do_softirq() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.133095 | 0) | __do_softirq() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.133153 | 0) + 43.064 us | run_timer_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.133245 | 0) ! 148.201 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.133260 | 0) ! 185.542 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.133272 | 0) ! 221.503 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.134684 | 0) + 47.945 us | irq_enter();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.134785 | 0) + 19.704 us | raise_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.134911 | 0) | irq_exit() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.134931 | 0) | do_softirq() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.134949 | 0) | __do_softirq() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135019 | 0) + 17.437 us | irq_enter();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135080 | 0) + 18.143 us | raise_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135165 | 0) + 19.679 us | irq_exit();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135230 | 0) + 39.134 us | run_timer_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135307 | 0) + 33.181 us | run_timer_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135384 | 0) ! 434.587 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135398 | 0) ! 468.233 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135408 | 0) ! 500.772 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">——————————————</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0) <…>-1855 => vsftpd-2125</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">——————————————</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135778 | 0) + 43.128 us | irq_enter();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.135900 | 0) + 18.773 us | raise_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.136019 | 0) | irq_exit() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.136037 | 0) | do_softirq() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.136052 | 0) | __do_softirq() {</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.136100 | 0) + 37.945 us | run_timer_softirq();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.136179 | 0) ! 125.562 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.136192 | 0) ! 155.517 us | }</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8919.136201 | 0) ! 184.853 us | }</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;"><strong>Latency Tracing</strong></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>1, irqsoff tracer</strong></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>設定路徑為</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Kernel hacking —>Tracers —>Interrupts-off Latency Tracer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">主要用來</span><span style="font-family: "Times New Roman", serif;">Tracing</span><span style="font-family: "Times New Roman", serif;">中斷被關閉的行為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">並且會把關閉最久的時間與對應的呼叫動作顯示出來</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">提供系統效能分析的判斷之用</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">例如</span><span style="font-family: "Times New Roman", serif;">:</span><span style="font-family: "Times New Roman", serif;">當在中斷中做了過多</span><span style="font-family: "Times New Roman", serif;">I/O</span><span style="font-family: "Times New Roman", serif;">的行為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就會對系統效能造成影響</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">透過分析可以把這類設計移到</span><span style="font-family: "Times New Roman", serif;">Bottom-Half (HISR)</span><span style="font-family: "Times New Roman", serif;">中處理</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">減少系統把中斷關閉所導致的效能影響</span><span style="font-family: "Times New Roman", serif;">. (</span><span style="font-family: "Times New Roman", serif;">屬於</span><span style="font-family: "Times New Roman", serif;">I/O</span><span style="font-family: "Times New Roman", serif;">的等待應該放到系統閒置的時間才處理</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在中斷裡要越快結束越好</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">把處理器執行時間讓給優先級高的</span><span style="font-family: "Times New Roman", serif;">Task).</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">執行範例如下所示</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo nop > current_tracer</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo irqsoff > current_tracer</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 1 > tracing_enabled</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># sleep 3</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 0 >tracing_enabled</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">顯示結果如下</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># tracer: irqsoff</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>#</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># irqsoff latency trace v1.1.5 on 2.6.38.6</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># ——————————————————————–</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># latency: 10747 us, #123/123, CPU#0 | (M:desktop VP:0, KP:0, SP:0 HP:0 #P:1)</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># —————–</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># | task: vsftpd-1961 (uid:0 nice:0 policy:0 rt_prio:0)</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># —————–</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># => started at: __make_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># => ended at: __blk_run_queue</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>#</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>#</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># _——=> CPU#</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># / _—–=> irqs-off</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># | / _—-=> need-resched</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># || / _—=> hardirq/softirq</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># ||| / _–=> preempt-depth</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># |||| /_–=> lock-depth</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># |||||/ delay</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># cmd pid |||||| time | caller</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong># \ / |||||| \ | /</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 23us+: _raw_spin_lock_irq <-__make_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 103us+: cpu_coregroup_mask <-__make_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 118us!: elv_queue_empty <-__make_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 997us+: cfq_queue_empty <-elv_queue_empty</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1055us+: blk_plug_device <-__make_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1109us!: mod_timer <-blk_plug_device</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1216us+: lock_timer_base <-mod_timer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1231us+: _raw_spin_lock_irqsave <-lock_timer_base</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1253us+: internal_add_timer <-mod_timer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1270us+: _raw_spin_unlock_irqrestore <-mod_timer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1369us!: drive_stat_acct <-__make_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1480us!: disk_map_sector_rcu <-drive_stat_acct</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1713us+: part_round_stats <-drive_stat_acct</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1782us+: part_round_stats_single <-part_round_stats</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1832us!: part_round_stats_single <-part_round_stats</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1938us+: __elv_add_request <-__make_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 1993us!: elv_insert <-__elv_add_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 2100us!: elv_rqhash_add <-elv_insert</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 2259us+: cfq_insert_request <-elv_insert</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 2330us+: cfq_init_prio_data <-cfq_insert_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 2421us+: cfq_add_rq_rb <-cfq_insert_request</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 2489us!: elv_rb_add <-cfq_add_rq_rb</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 2637us+: cfq_resort_rr_list <-cfq_add_rq_rb</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 2689us+: cfq_service_tree_add <-cfq_resort_rr_list</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 2724us+: cfqq_type <-cfq_service_tree_add</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>..</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 10463us+: _raw_spin_lock_irqsave <-lock_timer_base</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 10476us+: internal_add_timer <-mod_timer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 10490us+: _raw_spin_unlock_irqrestore <-mod_timer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 10562us!: _raw_spin_lock <-scsi_request_fn</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 10736us+: scsi_request_fn <-__blk_run_queue</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>vsftpd-1961 0dN… 10760us+: trace_hardirqs_on <-__blk_run_queue</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">其中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">中間六個屬性數值意義分別為</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,CPU : </span><span style="font-family: "Times New Roman", serif;">該任務所運作的</span><span style="font-family: "Times New Roman", serif;">CPU ID</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,irqs-off : ‘d’=</span><span style="font-family: "Times New Roman", serif;">關閉中斷</span><span style="font-family: "Times New Roman", serif;">, ‘.’=</span><span style="font-family: "Times New Roman", serif;">中斷沒關閉</span><span style="font-family: "Times New Roman", serif;">,’X’=</span><span style="font-family: "Times New Roman", serif;">該平台不支援讀取</span><span style="font-family: "Times New Roman", serif;">IRQ Flag</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,need-resched: ‘N’=need_resched</span><span style="font-family: "Times New Roman", serif;">被設置</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">表示行程會重新排程</span><span style="font-family: "Times New Roman", serif;">), ‘.’=</span><span style="font-family: "Times New Roman", serif;">前項不成立</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4,hardirq/softirq: ‘H’=</span><span style="font-family: "Times New Roman", serif;">在軟體中斷進行過程中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">發生的硬體中斷 </span><span style="font-family: "Times New Roman", serif;">, ‘h’ =</span><span style="font-family: "Times New Roman", serif;">正在硬體中斷處理中</span><span style="font-family: "Times New Roman", serif;">, ‘s’ =</span><span style="font-family: "Times New Roman", serif;">正在軟體中斷處理中</span><span style="font-family: "Times New Roman", serif;">, ‘.’ =</span><span style="font-family: "Times New Roman", serif;">一般行程運作中</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">5,preempt-depth: </span><span style="font-family: "Times New Roman", serif;">表示</span><span style="font-family: "Times New Roman", serif;">preempt_disabled</span><span style="font-family: "Times New Roman", serif;">的</span><span style="font-family: "Times New Roman", serif;">Level</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">6,lock-depth:</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">接下來屬於 </span><span style="font-family: "Times New Roman", serif;">time</span><span style="font-family: "Times New Roman", serif;">的欄位</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">單位為 </span><span style="font-family: "Times New Roman", serif;">us,</span><span style="font-family: "Times New Roman", serif;">代表的是從呼叫的函式到被呼叫的函式所經過的時間</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">這段時間如果超過 </span><span style="font-family: "Times New Roman", serif;">preempt_mark_thresh (default 100)</span><span style="font-family: "Times New Roman", serif;">的值</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">時間後面就會標示 </span><span style="font-family: "Times New Roman", serif;">‘!’,</span><span style="font-family: "Times New Roman", serif;">如果超過</span><span style="font-family: "Times New Roman", serif;">1</span><span style="font-family: "Times New Roman", serif;">個</span><span style="font-family: "Times New Roman", serif;">us,</span><span style="font-family: "Times New Roman", serif;">就會標示 </span><span style="font-family: "Times New Roman", serif;">‘+’,</span><span style="font-family: "Times New Roman", serif;">如果小於或等於</span><span style="font-family: "Times New Roman", serif;">1us</span><span style="font-family: "Times New Roman", serif;">則部會標示任何符號</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">以這例子來說</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">起點會在函式</span><span style="font-family: "Times New Roman", serif;">__make_request (</span><span style="font-family: "Times New Roman", serif;">實作在</span><span style="font-family: "Times New Roman", serif;">block/blk-core.c</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">) </span><span style="font-family: "Times New Roman", serif;">呼叫</span><span style="font-family: "Times New Roman", serif;">spin_lock_irq</span><span style="font-family: "Times New Roman", serif;">關閉硬體中斷</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">最後在函式</span><span style="font-family: "Times New Roman", serif;">__blk_run_queue(</span><span style="font-family: "Times New Roman", serif;">實作在</span><span style="font-family: "Times New Roman", serif;">block/blk-core.c</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">)</span><span style="font-family: "Times New Roman", serif;">後</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">恢復硬體中斷運作</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: maroon;"><strong>=></strong></span></span><span style="color: maroon;"><span style="font-family: "Times New Roman", serif;"><strong>恢復中斷的流程</strong></span><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span></span><span style="color: maroon;"><span style="font-family: "Times New Roman", serif;"><strong>是呼叫函式</strong></span><span style="font-family: "Times New Roman", serif;"><strong>trace_hardirqs_on(</strong></span></span><span style="color: maroon;"><span style="font-family: "Times New Roman", serif;"><strong>實作在</strong></span><span style="font-family: "Times New Roman", serif;"><strong>kernel/lockdep.c</strong></span></span><span style="color: maroon;"><span style="font-family: "Times New Roman", serif;"><strong>中</strong></span><span style="font-family: "Times New Roman", serif;"><strong>),</strong></span></span><span style="color: maroon;"><span style="font-family: "Times New Roman", serif;"><strong>再呼叫到函式</strong></span><span style="font-family: "Times New Roman", serif;"><strong>trace_hardirqs_on_caller(</strong></span></span><span style="color: maroon;"><span style="font-family: "Times New Roman", serif;"><strong>實作在</strong></span><span style="font-family: "Times New Roman", serif;"><strong>kernel/lockdep.c</strong></span></span><span style="color: maroon;"><span style="font-family: "Times New Roman", serif;"><strong>中</strong></span><span style="font-family: "Times New Roman", serif;"><strong>),</strong></span></span><span style="color: maroon;"><span style="font-family: "Times New Roman", serif;"><strong>完成恢復硬體中斷的動作</strong></span><span style="font-family: "Times New Roman", serif;"><strong>.</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>2, Wakeup tracer</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Scheduling Latency Tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可用以顯示 </span><span style="font-family: "Times New Roman", serif;">Real-Time Task</span><span style="font-family: "Times New Roman", serif;">取得執行權所需等待的時間</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">操作範例如下所示</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo wakeup > current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 1 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># chrt -f 10 ps <span style="color: red;"><strong>==></strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>用</strong></span><span style="font-family: "Times New Roman", serif;"><strong>real-Time </strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>權限</strong></span><span style="font-family: "Times New Roman", serif;"><strong>10</strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>執行 </strong></span><span style="font-family: "Times New Roman", serif;"><strong>ps </strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>指令</strong></span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">執行結果如下</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: wakeup</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># wakeup latency trace v1.1.5 on 2.6.38.6</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># ——————————————————————–</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># latency: 5961 us, #149/149, CPU#0 | (M:desktop VP:0, KP:0, SP:0 HP:0 #P:1)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># —————–</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | task: kworker/0:1-9481 (uid:0 nice:0 policy:0 rt_prio:0)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># —————–</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># _——=> CPU#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># / _—–=> irqs-off</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | / _—-=> need-resched</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># || / _—=> hardirq/softirq</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># ||| / _–=> preempt-depth</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># |||| /_–=> lock-depth</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># |||||/ delay</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># cmd pid |||||| time | caller</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># \ / |||||| \ | /</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dNs.. 15us!: 1892:139:R + [000] 9481:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dNs.. 171us+: wake_up_process <-wake_up_worker</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dNs.. 187us+: check_preempt_curr <-try_to_wake_up</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dNs.. 199us+: check_preempt_wakeup <-check_preempt_curr</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dNs.. 214us+: update_curr <-check_preempt_wakeup</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0.N… 5392us+: mutex_lock <-inotify_poll</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0.N… 5416us+: _cond_resched <-mutex_lock</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0.N… 5431us!: __cond_resched <-_cond_resched</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0.N… 5668us+: schedule <-__cond_resched</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0.N… 5697us+: rcu_note_context_switch <-schedule</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0.N… 5727us+: rcu_sched_qs <-rcu_note_context_switch</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0.N… 5755us+: _raw_spin_lock_irq <-schedule</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5785us+: update_rq_clock <-schedule</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5798us+: put_prev_task_fair <-schedule</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5805us+: update_curr <-put_prev_task_fair</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5812us+: check_spread <-put_prev_task_fair</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5821us+: __enqueue_entity <-put_prev_task_fair</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5839us+: pick_next_task_fair <-schedule</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5845us+: __pick_next_entity <-pick_next_task_fair</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5853us+: clear_buddies <-pick_next_task_fair</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5862us+: set_next_entity <-pick_next_task_fair</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5869us+: update_stats_wait_end <-set_next_entity</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0dN… 5880us+: __dequeue_entity <-set_next_entity</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0d…. 5937us+: schedule <-__cond_resched</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_serv-1892 0d…. 5943us : 1892:139:R ==> [000] 9481:120:R kworker/0:1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">根據上述的結果</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我們可以看到花了約</span><span style="font-family: "Times New Roman", serif;">5961us</span><span style="font-family: "Times New Roman", serif;">從由</span><span style="font-family: "Times New Roman", serif;">kworker</span><span style="font-family: "Times New Roman", serif;">交出執行權到重新取得執行權</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">上面的列表中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">包括了超過 </span><span style="font-family: "Times New Roman", serif;">1us</span><span style="font-family: "Times New Roman", serif;">的函式呼叫標示為</span><span style="font-family: "Times New Roman", serif;">‘+’,</span><span style="font-family: "Times New Roman", serif;">與超過</span><span style="font-family: "Times New Roman", serif;">100us</span><span style="font-family: "Times New Roman", serif;">的函式呼叫標示為</span><span style="font-family: "Times New Roman", serif;">‘!’,</span><span style="font-family: "Times New Roman", serif;">以如下的行為來說</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就是從函式</span><span style="font-family: "Times New Roman", serif;">set_next_entity</span><span style="font-family: "Times New Roman", serif;">呼叫函式 </span><span style="font-family: "Times New Roman", serif;">update_stats_wait_end</span><span style="font-family: "Times New Roman", serif;">到函式</span><span style="font-family: "Times New Roman", serif;">set_next_entity</span><span style="font-family: "Times New Roman", serif;">呼叫函式</span><span style="font-family: "Times New Roman", serif;">__dequeue_entity ,</span><span style="font-family: "Times New Roman", serif;">中間間隔了 </span><span style="font-family: "Times New Roman", serif;">5880-5869=11us</span><span style="font-family: "Times New Roman", serif;">的時間</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">因為超過</span><span style="font-family: "Times New Roman", serif;">1us</span><span style="font-family: "Times New Roman", serif;">所以標示為</span><span style="font-family: "Times New Roman", serif;">‘+’)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">gam_serv-1892 0dN… 5869us+: update_stats_wait_end <-set_next_entity</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">gam_serv-1892 0dN… 5880us+: __dequeue_entity <-set_next_entity</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">或是</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">gam_serv-1892 0.N… 5431us!: __cond_resched <-_cond_resched</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">gam_serv-1892 0.N… 5668us+: schedule <-__cond_resched</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;"><strong>Task Context-Switch Schedule tracer</strong></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Scheduling Latency Tracer</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">用以解析</span><span style="font-family: "Times New Roman", serif;">Task Context-Switch</span><span style="font-family: "Times New Roman", serif;">的資訊</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">可以參考如下的範例</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo > /data/debug/tracing/trace <span style="color: red;"><strong>=></strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>清空</strong></span><span style="font-family: "Times New Roman", serif;"><strong>trace</strong></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>內容</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo sched_switch > /data/debug/tracing/current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 1 > /data/debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># sleep 1</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 0 > /data/debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat /data/debug/tracing/trace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: sched_switch</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">events/0-4 [000] 1044.598519: 4:115:S ==> [000] 87:120:R AlarmManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AlarmManager-87 [000] 1044.598749: 87:120:R + [000] 69:118:S ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AlarmManager-87 [000] 1044.599057: 87:120:R ==> [000] 69:118:R ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ActivityManager-69 [000] 1044.599411: 69:118:S ==> [000] 87:120:R AlarmManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AlarmManager-87 [000] 1044.599643: 87:120:R + [000] 69:118:S ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AlarmManager-87 [000] 1044.599957: 87:120:R ==> [000] 69:118:R ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ActivityManager-69 [000] 1044.600498: 69:118:S ==> [000] 87:120:R AlarmManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AlarmManager-87 [000] 1044.600929: 87:120:R + [000] 69:118:S ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AlarmManager-87 [000] 1044.601509: 87:120:R ==> [000] 69:118:R ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ActivityManager-69 [000] 1044.602102: 69:118:R + [000] 72:120:S ProcessStats</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ActivityManager-69 [000] 1044.604484: 69:118:R + [000] 67:118:S er.ServerThread</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ActivityManager-69 [000] 1044.604661: 69:118:R ==> [000] 67:118:R er.ServerThread</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">er.ServerThread-67 [000] 1044.605145: 67:118:S ==> [000] 72:120:R ProcessStats</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ProcessStats-72 [000] 1044.611966: 72:120:R ==> [000] 69:118:R ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">如上所示</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">所列出的數據分別包含</span><span style="font-family: "Times New Roman", serif;">Task ID/Name,</span><span style="font-family: "Times New Roman", serif;">運作的處理器</span><span style="font-family: "Times New Roman", serif;">ID(</span><span style="font-family: "Times New Roman", serif;">供多核心的環境分析</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">每次觸發的時間值</span><span style="font-family: "Times New Roman", serif;">, </span><span style="font-family: "Times New Roman", serif;">如下以上述例子做一些說明</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AlarmManager-87 [000] 1044.600929: 87:120:R + [000] 69:118:S ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>=>PID 87,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>120,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Running,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>AlarmManager, </strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>會喚醒 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>PID 69,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>118,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Sleep</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ActivityManager</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AlarmManager-87 [000] 1044.601509: 87:120:R ==> [000] 69:118:R ActivityManager</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>=>PID 87,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>120,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Running,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>AlarmManager, </strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>會把執行權切換</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>(Context-Switch)</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>到 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>PID 69,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>118,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Running</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ActivityManager</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ActivityManager-69 [000] 1044.602102: 69:118:R + [000] 72:120:S ProcessStats</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>=>PID 69,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>118,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Running,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ActivityManager, </strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>會喚醒 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>PID 72,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>120,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Sleep</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ProcessStats</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ActivityManager-69 [000] 1044.604484: 69:118:R + [000] 67:118:S er.ServerThread</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>=>PID 69,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>118,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Running,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ActivityManager, </strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>會喚醒 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>PID 67,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>118,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Sleep</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>er.ServerThread</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ActivityManager-69 [000] 1044.604661: 69:118:R ==> [000] 67:118:R er.ServerThread</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>=>PID 69,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>118,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Running,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ActivityManager , </strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>會把執行權切換</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>(Context-Switch)</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>到 </strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>PID 67,</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>執行優先級</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>118,Task</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>狀態為</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Running</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>運作在處理器</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>的</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>er.ServerThread</strong></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>有關</strong></span><span style="font-family: "Times New Roman", serif;"><strong>Task Priority </strong></span><span style="font-family: "Times New Roman", serif;"><strong>參考如下表</strong></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>(</strong></span><span style="font-family: "Times New Roman", serif;"><strong>技術部分也可以參考筆者這篇文章 </strong></span><span style="font-family: "Times New Roman", serif;"><strong>Linux 2.4/2.6 </strong></span><span style="font-family: "Times New Roman", serif;"><strong>核心排程機制剖析 ”</strong></span><span style="font-family: "Times New Roman", serif;"><strong>http://loda.hala01.com/2009/04/linux-2426-%e6%a0%b8%e5%bf%83%e6%8e%92%e7%a8%8b%e6%a9%9f%e5%88%b6%e5%89%96%e6%9e%90/”)</strong></span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 527px;"><colgroup><col width="166"></col><col width="344"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="166"><span style="font-family: "Times New Roman", serif;">Kernel task priority</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="344"><span style="font-family: "Times New Roman", serif;">說明</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="166"><span style="font-family: "Times New Roman", serif;">0 to 99</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="344"><span style="font-family: "Times New Roman", serif;">Real-Time priority 99 to 0</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="166"><span style="font-family: "Times New Roman", serif;">100 to 139</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="344"><span style="font-family: "Times New Roman", serif;">對應到</span><span style="font-family: "Times New Roman", serif;">Task Nice Value -20 to 19</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="166"><span style="font-family: "Times New Roman", serif;">140</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="344"><span style="font-family: "Times New Roman", serif;">idle task priority</span></td></tr>
</tbody></table>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>有關</strong></span><span style="font-family: "Times New Roman", serif;"><strong>Task </strong></span><span style="font-family: "Times New Roman", serif;"><strong>狀態 參考如下表</strong></span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 527px;"><colgroup><col width="147"></col><col width="362"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="147"><span style="font-family: "Times New Roman", serif;">狀態符號</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="362"><span style="font-family: "Times New Roman", serif;">說明</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="147"><span style="font-family: "Times New Roman", serif;">R (Running)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="362"><span style="font-family: "Times New Roman", serif;">Wants to run, may not</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="147"><span style="font-family: "Times New Roman", serif;">S (Sleep)ctually be running</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="362"><span style="font-family: "Times New Roman", serif;">Process is waiting to be woken up (handles signals)</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="147"><span style="font-family: "Times New Roman", serif;">D (Disk sleep)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="362"><span style="font-family: "Times New Roman", serif;">(uninterruptible sleep) Process must be woken up (ignores signals)</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="147"><span style="font-family: "Times New Roman", serif;">T (Stopped)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="362"><span style="font-family: "Times New Roman", serif;">Process suspended</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="147"><span style="font-family: "Times New Roman", serif;">t (Traced)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="362"><span style="font-family: "Times New Roman", serif;">Process is being traced (with something like gdb)</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="147"><span style="font-family: "Times New Roman", serif;">Z (Zombie)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="362"><span style="font-family: "Times New Roman", serif;">Process waiting to be cleaned up</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="147"><span style="font-family: "Times New Roman", serif;">X (Unknown)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="362"></td></tr>
</tbody></table>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;"><strong>Block Device Tracer</strong></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Support for tracing block io actions</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可以用來監控儲存裝置的使用狀況</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">與行為</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">例如筆者要啟動</span><span style="font-family: "Times New Roman", serif;">Block Device Tracer</span><span style="font-family: "Times New Roman", serif;">監控目前正在編譯程式碼的儲存裝置</span><span style="font-family: "Times New Roman", serif;">sda2,</span><span style="font-family: "Times New Roman", serif;">如下操作指令</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 >/sys/block/sda/sda2/trace/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo blk > current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">..</span><span style="font-family: "Times New Roman", serif;">執行編譯的行為</span><span style="font-family: "Times New Roman", serif;">….</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > /debug/tracing/tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 >/sys/block/sda/sda2/trace/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">再來檢視 </span><span style="font-family: "Times New Roman", serif;">trace</span><span style="font-family: "Times New Roman", serif;">中的結果如下所示</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: blk</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mv-21550 [000] 6663.719323: 8,2 m N cfq21550 sl_used=4 disp=1 charge=4 iops=0 sect=8</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mv-21550 [000] 6663.719341: 8,2 m N cfq21550 del_from_rr</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mv-21550 [000] 6663.719367: 8,2 m N cfq21550 put_queue</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.920569: 8,2 A R 221728392 + 56 <- (253,0) 221728008</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.920576: 8,2 A R 221937237 + 56 <- (8,2) 221728392</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.920577: 8,2 Q R 221937237 + 56 [cc1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.920751: 8,2 m N cfq21557 alloced</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.920816: 8,2 G R 221937237 + 56 [cc1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.920875: 8,2 P N [cc1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.921844: 8,2 I R 221937237 + 56 [cc1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.921870: 8,2 m N cfq21557 insert_request</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-21557 [000] 6663.921906: 8,2 m N cfq21557 add_to_rr</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">as-21558 [000] 6663.923906: 8,2 UT N [as] 1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:1-16318 [000] 6663.924047: 8,2 U N [kworker/0:1] 1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:1-16318 [000] 6663.924102: 8,2 m N cfq workload slice:100</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:1-16318 [000] 6663.924146: 8,2 m N cfq21557 set_active wl_prio:0 wl_type:2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">…………..</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ld-21578 [000] 6665.826767: 8,2 U N [ld] 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ld-21578 [000] 6665.826865: 8,2 U N [ld] 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ld-21578 [000] 6665.829130: 8,2 U N [ld] 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ld-21578 [000] 6665.831853: 8,2 U N [ld] 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ld-21578 [000] 6665.839538: 8,2 m N cfq21578 put_queue</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-21532 [000] 6665.902373: 8,2 m N cfq21532 put_queue</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920115: 8,2 A R 221728880 + 8 <- (253,0) 221728496</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920121: 8,2 A R 221937725 + 8 <- (8,2) 221728880</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920123: 8,2 Q R 221937725 + 8 [make]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920468: 8,2 m N cfq21583 alloced</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920646: 8,2 G R 221937725 + 8 [make]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920691: 8,2 P N [make]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920741: 8,2 I R 221937725 + 8 [make]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920770: 8,2 m N cfq21583 insert_request</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920800: 8,2 m N cfq21583 add_to_rr</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920861: 8,2 U N [make] 1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920897: 8,2 m N cfq workload slice:100</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-21583 [000] 6665.920923: 8,2 m N cfq21583 set_active wl_prio:0 wl_type:2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">…………..</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;"><strong>Branch tracer</strong></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>1, Trace likely/unlikely profiler</strong></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Branch Profiling —>Trace likely/unlikely profiler</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">用以顯示</span><span style="font-family: "Times New Roman", serif;">Kernel</span><span style="font-family: "Times New Roman", serif;">基於</span><span style="font-family: "Times New Roman", serif;">likely/unlikely</span><span style="font-family: "Times New Roman", serif;">的</span><span style="font-family: "Times New Roman", serif;">Run-Time</span><span style="font-family: "Times New Roman", serif;">統計結果</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">操作範例如下所示</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo branch > current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">..do something…..</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">查看結果如下</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: branch</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP CORRECT FUNC:FILE:LINE</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.397835: [ ok ] read_seqretry:seqlock.h:110</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.397848: [ ok ] native_sched_clock:tsc.c:55</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.397859: [ ok ] native_sched_clock:tsc.c:55</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.398682: [ ok ] __local_bh_enable:softirq.c:138</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.398695: [ ok ] update_wall_time:timekeeping.c:789</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.398710: [ MISS ] timekeeping_adjust:timekeeping.c:711</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.398725: [ ok ] update_wall_time:timekeeping.c:839</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.398734: [ ok ] update_wall_time:timekeeping.c:859</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">..</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.401654: [ ok ] update_wall_time:timekeeping.c:789</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.401668: [ MISS ] timekeeping_adjust:timekeeping.c:711</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.401677: [ ok ] update_wall_time:timekeeping.c:839</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 55415.401687: [ ok ] update_wall_time:timekeeping.c:859</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">..</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">針對</span><span style="font-family: "Times New Roman", serif;">MISS</span><span style="font-family: "Times New Roman", serif;">比較多的段落寫法</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我們可以透過修改</span><span style="font-family: "Times New Roman", serif;">likely/unlikely</span><span style="font-family: "Times New Roman", serif;">的配置</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">讓</span><span style="font-family: "Times New Roman", serif;">gcc __builtin_expect</span><span style="font-family: "Times New Roman", serif;">的函式發揮作用</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">把真正的熱區放在循序的執行過程中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">非熱區放在需要</span><span style="font-family: "Times New Roman", serif;">Jump/Branch</span><span style="font-family: "Times New Roman", serif;">的位址</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">減少處理器</span><span style="font-family: "Times New Roman", serif;">Pipeline</span><span style="font-family: "Times New Roman", serif;">被</span><span style="font-family: "Times New Roman", serif;">Flush</span><span style="font-family: "Times New Roman", serif;">的機會</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">從而也可以讓系統的運作效率更佳</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>2, Profile all if conditionals</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Branch Profiling —>Profile all if conditionals</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">操作範例如下所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo branch > current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">..do something…..</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 0 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">查看結果如下</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: branch</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP CORRECT FUNC:FILE:LINE</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131833: [ ok ] native_sched_clock:tsc.c:55</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131843: [ ok ] native_sched_clock:tsc.c:55</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131850: [ ok ] sched_clock_local:sched_cloc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">k.c:149</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131860: [ ok ] sched_clock_cpu:sched_clock.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">c:219</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131866: [ ok ] sched_clock_cpu:sched_clock.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">c:219</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131873: [ ok ] sched_clock_cpu:sched_clock.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">c:224</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131879: [ ok ] native_sched_clock:tsc.c:55</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131886: [ ok ] sched_clock_local:sched_cloc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">k.c:149</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131896: [ ok ] update_curr:sched_fair.c:576</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131903: [ ok ] calc_delta_fair:sched_fair.c</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">:477</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131913: [ ok ] trace_sched_stat_runtime:sch</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ed.h:363:</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131922: [ ok ] __sched_period:sched_fair.c:496</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131928: [ ok ] sched_slice:sched_fair.c:521</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131935: [ MISS ] calc_delta_mine:sched.c:1327</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131942: [ ok ] resched_task:sched.c:1158</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131949: [ MISS ] test_tsk_need_resched:sched.h:2378</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131956: [ ok ] perf_event_task_tick:perf_event.c:1828</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131963: [ ok ] perf_event_task_tick:perf_event.c:1828</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131970: [ MISS ] trigger_load_balance:sched_fair.c:3989</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131978: [ ok ] run_posix_cpu_timers:posix-cpu-timers.c:1312</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.131995: [ ok ] __local_bh_disable:softirq.c:98</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.132002: [ ok ] __local_bh_disable:softirq.c:98</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.132032: [ ok ] trace_softirq_entry:irq.h:117</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1806 [000] 297.132054: [ ok ] trace_softirq_exit:irq.h:131</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;"><strong>Kernel memory tracer</strong></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;">內存</span><span style="font-family: "Times New Roman", serif;">tracer</span><span style="font-family: "Times New Roman", serif;">主要用來跟踪</span><span style="font-family: "Times New Roman", serif;">slab allocator</span><span style="font-family: "Times New Roman", serif;">的分配情況。包括</span><span style="font-family: "Times New Roman", serif;">kfree</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">kmem_cache_alloc </span><span style="font-family: "Times New Roman", serif;">等</span><span style="font-family: "Times New Roman", serif;">API </span><span style="font-family: "Times New Roman", serif;">的調用情況,用戶程序可以根據</span><span style="font-family: "Times New Roman", serif;">tracer </span><span style="font-family: "Times New Roman", serif;">收集到的信息分析內部碎片情況,找出內存分配最頻繁的代碼片斷,等等</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Trace SLAB allocations</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">操作範例如下所示</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 0 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo kmemtrace > current_tracer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 1 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 0 > tracing_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">.etc</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;"><strong>Workqueue statistical tracer</strong></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;">這是一個</span><span style="font-family: "Times New Roman", serif;">statistic tracer</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">主要用來</span><span style="font-family: "Times New Roman", serif;">統計系統所有</span><span style="font-family: "Times New Roman", serif;">workqueue</span><span style="font-family: "Times New Roman", serif;">現況</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">可以知道有多少</span><span style="font-family: "Times New Roman", serif;">work</span><span style="font-family: "Times New Roman", serif;">被插入到</span><span style="font-family: "Times New Roman", serif;">queue</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以及有多少被執行</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">work</span><span style="font-family: "Times New Roman", serif;">的名稱</span><span style="font-family: "Times New Roman", serif;">, </span><span style="font-family: "Times New Roman", serif;">可用以提供開發端對於</span><span style="font-family: "Times New Roman", serif;">workqueue</span><span style="font-family: "Times New Roman", serif;">機制實現的參考</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Trace workqueues,</span><span style="font-family: "Times New Roman", serif;">系統啟動後</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">可以到</span><span style="font-family: "Times New Roman", serif;">/data/debug/tracing/trace_stat/workqueues</span><span style="font-family: "Times New Roman", serif;">下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">查看內容</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">如下所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># CPU INSERTED EXECUTED NAME</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># | | | |</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 2139 2139 events/0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 0 0 khelper</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 0 0 suspend</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 1 1 kblockd/0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 1 1 kmmcd</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 0 0 aio/0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 0 0 crypto/0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 0 0 rpciod/0</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;">Profiling</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>1,unlikely/likely</strong></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可用以顯示 </span><span style="font-family: "Times New Roman", serif;">likely/unlikely </span><span style="font-family: "Times New Roman", serif;">條件判斷式的統計結果</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">統計結果位於 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace_stat/branch_annotated</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">如下所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">correct incorrect % Function File Line</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">——- ——— – ——– —- —-</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 tcp_synack_options tcp_output.c 535</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 tcp_synack_options tcp_output.c 529</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 tcp_synack_options tcp_output.c 524</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 9 100 tcp_options_write tcp_output.c 397</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 3622 100 tcp_established_options tcp_output.c 562</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 7 100 sys_inotify_add_watch inotify_user.c 750</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 7 100 fput_light file.h 29</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 17920 100 get_futex_key futex.c 269</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 28 100 clocksource_adjust timekeeping.c 472</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 4 100 blocking_notifier_chain_regist notifier.c 220</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 signal_pending sched.h 2251</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 6849 100 trace_workqueue_execution workqueue.h 53</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 8 100 trace_workqueue_creation workqueue.h 76</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 6849 100 trace_workqueue_insertion workqueue.h 31</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 38 100 yield_task_fair sched_fair.c 1016</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 25617 100 _pick_next_task_rt sched_rt.c 1041</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 92856 100 sched_info_switch sched_stats.h 269</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 85509 100 sched_info_queued sched_stats.h 222</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 54733 100 sched_info_dequeued sched_stats.h 177</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 consistent_init dma-mapping.c 470</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">9 1710 99 tcp_options_write tcp_output.c 396</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 354 99 disk_put_part genhd.h 209</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">606 67234 99 fput_light file.h 29</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">35 9260 99 trace_kmalloc kmem.h 79</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">313 12957 97 fput_light file.h 29</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">542 10337 95 sys_gettimeofday time.c 111</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">70 770 91 blk_update_request blk-core.c 1968</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">28116 135585 82 fget_light file_table.c 332</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 8 80 trace_kmalloc kmem.h 79</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">24893 53424 68 fput_light file.h 29</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">4547 8951 66 need_resched sched.h 2273</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">750 1338 64 fput_light file.h 29</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">15323 25008 62 wakeup_gran sched_fair.c 1382</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">44 61 58 mmdrop sched.h 2024</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">821 1006 55 pskb_trim_rcsum skbuff.h 1690</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">84797 95325 52 calc_delta_fair sched_fair.c 400</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 1 50 remap_pte_range memory.c 1634</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">270 270 50 isolate_lru_pages vmscan.c 926</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">32028 27195 45 rmqueue_bulk page_alloc.c 907</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1970 1505 43 copy_pte_range memory.c 618</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">24549 17984 42 trace_kfree kmem.h 208</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>2,branche all</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可用以顯示所有 </span><span style="font-family: "Times New Roman", serif;">if</span><span style="font-family: "Times New Roman", serif;">條件判斷式的統計結果</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">統計結果位於 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace_stat/branch_all</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">如下所示</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">miss hit % Function File Line</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">——- ——— – ——– —- —-</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 i386_start_kernel head32.c 50</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 reserve_ebda_region head.c 51</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 reserve_ebda_region head.c 47</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 reserve_ebda_region head.c 42</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X nrcpus main.c 167</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X maxcpus main.c 178</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1098 0 0 do_one_initcall main.c 773</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1098 0 0 do_one_initcall main.c 769</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1098 0 0 do_one_initcall main.c 765</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1098 0 0 do_one_initcall main.c 762</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1098 0 0 do_one_initcall main.c 755</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 start_kernel main.c 682</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 start_kernel main.c 675</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 start_kernel main.c 661</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 start_kernel main.c 647</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 start_kernel main.c 630</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 start_kernel main.c 611</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 kernel_init main.c 914</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 kernel_init main.c 911</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 kernel_init main.c 901</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 smp_init main.c 399</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 smp_init main.c 397</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 1 50 cpumask_next cpumask.h 172</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X init_post main.c 850</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 init_post main.c 838</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X unknown_bootoption main.c 321</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X unknown_bootoption main.c 313</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X unknown_bootoption main.c 309</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X unknown_bootoption main.c 305</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X unknown_bootoption main.c 302</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X unknown_bootoption main.c 299</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 2 100 unknown_bootoption main.c 295</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X unknown_bootoption main.c 286</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 1 100 unknown_bootoption main.c 284</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 1 50 unknown_bootoption main.c 282</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 2 100 obsolete_checksetup main.c 235</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 0 0 obsolete_checksetup main.c 231</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X obsolete_checksetup main.c 229</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2 0 0 obsolete_checksetup main.c 224</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">28 2 6 obsolete_checksetup main.c 223</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 1 50 parse_early_param main.c 496</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0 0 X do_early_param main.c 476</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">368 0 0 do_early_param main.c 475</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1 0 0 readonly do_mounts.c 44</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>3,Functions</strong></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可用以顯示所有函式執行次數與時間的統計結果</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">操作範例如下所示</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 1 > /debug/tracing/function_profile_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">..do something…..</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 0 > /debug/tracing/function_profile_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#cat /debug/tracing/trace_stat/function0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">可看到如下結果</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Function Hit Time Avg s^2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">——– — —- ——</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">schedule 752 99800000 us 132712.7 us 2635264000 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">poll_schedule_timeout 57 37432000 us 656701.7 us 2143996599 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">schedule_hrtimeout_range 55 37429000 us 680527.2 us 339918459 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">schedule_hrtimeout_range_clock 55 37424000 us 680436.3 us 237544596 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sys_select 87 25028000 us 287678.1 us 306802216 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">core_sys_select 87 25012000 us 287494.2 us 155578451 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">do_select 87 24875000 us 285919.5 us 323446561 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">smp_apic_timer_interrupt 15677 16056000 us 1024.175 us 76796.05 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">do_timer 15677 15677000 us 1000.000 us 0.000 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">tick_periodic 15677 15677000 us 1000.000 us 0.000 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">tick_handle_periodic 15677 15677000 us 1000.000 us 0.000 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sys_poll 14 14227000 us 1016214 us 3 503583162 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">do_sys_poll 14 14217000 us 1015500 us 3 379054126 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sys_nanosleep 15 13957000 us 930466.6 us 1834329984 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">hrtimer_nanosleep 15 13945000 us 929666.6 us 1719729983 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">do_nanosleep 15 13944000 us 929600.0 us 1710319131 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sys_read 167 13503000 us 80856.28 us 1298120022 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">vfs_read 172 13490000 us 78430.23 us 2981769264 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">tty_read 61 13297000 us 217983.6 us 2678381427 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">n_tty_read 61 13256000 us 217311.4 us 2834883001 us</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">schedule_timeout 20 12966000 us 648300.0 us 2458710875 us</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;">Max Stack Tracer</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;">可用以顯示核心函式呼叫最深的</span><span style="font-family: "Times New Roman", serif;">Stack</span><span style="font-family: "Times New Roman", serif;">大小與在該情況下的</span><span style="font-family: "Times New Roman", serif;">Call Stack</span><span style="font-family: "Times New Roman", serif;">路徑</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">設定路徑為</span><span style="font-family: "Times New Roman", serif;">Kernel hacking —>Tracers —>Trace max stack</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 1 > /proc/sys/kernel/stack_tracer_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># sleep 10</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># echo 0 > /proc/sys/kernel/stack_tracer_enabled</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># cat stack_max_size</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2152</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"># cat stack_trace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Depth Size Location (22 entries)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">—– —- ——–</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0) 2084 68 update_curr+0x100/0x210</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1) 2016 56 enqueue_task_fair+0x90/0x4e0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2) 1960 24 enqueue_task+0x8d/0xb0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3) 1936 12 activate_task+0x25/0x50</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4) 1924 88 try_to_wake_up+0x24a/0x5f0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">5) 1836 8 wake_up_process+0x14/0x20</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">6) 1828 8 hrtimer_wakeup+0x2c/0x30</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7) 1820 80 hrtimer_run_queues+0x1d4/0x480</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">8) 1740 8 run_local_timers+0xd/0x20</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">9) 1732 20 update_process_times+0x34/0x90</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">10) 1712 8 tick_periodic+0x7a/0x90</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">11) 1704 32 tick_handle_periodic+0x1e/0xb0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">12) 1672 8 smp_apic_timer_interrupt+0x9c/0x9e</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">13) 1664 108 apic_timer_interrupt+0x2f/0x34</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">14) 1556 232 schedule+0x62b/0x10f0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">15) 1324 76 schedule_hrtimeout_range_clock+0x14b/0x170</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">16) 1248 12 schedule_hrtimeout_range+0x17/0x20</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">17) 1236 20 poll_schedule_timeout+0x4c/0x70</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">18) 1216 764 do_select+0x789/0x7c0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">19) 452 332 core_sys_select+0x27d/0x460</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">20) 120 40 sys_select+0x40/0xe0</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">21) 80 80 syscall_call+0x7/0xb</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">主要會列出目前最深的</span><span style="font-family: "Times New Roman", serif;">Stack Size,</span><span style="font-family: "Times New Roman", serif;">與根據該</span><span style="font-family: "Times New Roman", serif;">Stack Size</span><span style="font-family: "Times New Roman", serif;">發生的情況下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">完整的</span><span style="font-family: "Times New Roman", serif;">Call Stack</span><span style="font-family: "Times New Roman", serif;">流程與每個函式所佔的空間</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">會包括區域變數與</span><span style="font-family: "Times New Roman", serif;">Function Parameters</span><span style="font-family: "Times New Roman", serif;">所佔的</span><span style="font-family: "Times New Roman", serif;">Stack</span><span style="font-family: "Times New Roman", serif;">空間</span><span style="font-family: "Times New Roman", serif;">).</span><span style="font-family: "Times New Roman", serif;">讓開發者</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">可以根據這流程去檢討函式與呼叫流程設計的合理性</span><span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;">Event tracing</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"><span style="font-family: "Times New Roman", serif;">Event</span><span style="font-family: "Times New Roman", serif;">幾乎是整個</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">各種資訊的集合</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">瀏覽</span><span style="font-family: "Times New Roman", serif;">/debug/tracing/events</span><span style="font-family: "Times New Roman", serif;">目錄中的檔案名稱如下所示</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 4 root root 0 XXX 20 23:55 bkl</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 20 root root 0 XXX 20 23:55 block</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">-rw-r–r– 1 root root 0 XXX 20 23:55 enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 14 root root 0 XXX 20 23:55 ftrace</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">-r–r–r– 1 root root 0 XXX 20 23:55 header_event</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">-r–r–r– 1 root root 0 XXX 20 23:55 header_page</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 7 root root 0 XXX 20 23:55 irq</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 14 root root 0 XXX 20 23:55 kmem</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 3 root root 0 XXX 20 23:55 mce</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 7 root root 0 XXX 20 23:55 module</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 3 root root 0 XXX 20 23:55 napi</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 6 root root 0 XXX 20 23:55 net</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 12 root root 0 XXX 20 23:55 power</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 4 root root 0 XXX 20 23:55 raw_syscalls</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 18 root root 0 XXX 20 23:55 sched</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 7 root root 0 XXX 20 23:55 scsi</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 6 root root 0 XXX 20 23:55 signal</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 5 root root 0 XXX 20 23:55 skb</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 634 root root 0 XXX 20 23:55 syscalls</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 14 root root 0 XXX 20 23:55 timer</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 15 root root 0 XXX 20 23:55 vmscan</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 6 root root 0 XXX 20 23:55 workqueue</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">drwxr-xr-x 23 root root 0 XXX 20 23:55 writeback</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">除了 </span><span style="font-family: "Times New Roman", serif;">enable,header_event</span><span style="font-family: "Times New Roman", serif;">與</span><span style="font-family: "Times New Roman", serif;">header_page</span><span style="font-family: "Times New Roman", serif;">這三個控制檔案外</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">其他每個目錄都包含一種類別的</span><span style="font-family: "Times New Roman", serif;">Event</span><span style="font-family: "Times New Roman", serif;">參數</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">以目前筆者所使用的環境</span><span style="font-family: "Times New Roman", serif;">,Event</span><span style="font-family: "Times New Roman", serif;">包含了以下的類別</span></div>
<table border="1" bordercolor="#000000" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 525px;"><colgroup><col width="89"></col><col width="419"></col></colgroup><tbody>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">名稱</span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">說明</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">bkl</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">BKL</span><span style="font-family: "Times New Roman", serif;">為</span><span style="font-family: "Times New Roman", serif;">Linux Kernel 2.2</span><span style="font-family: "Times New Roman", serif;">時</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">為了提供一個暫時簡易的支援</span><span style="font-family: "Times New Roman", serif;">SMP</span><span style="font-family: "Times New Roman", serif;">機制</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">除了讓多核心的架構可以支援多個</span><span style="font-family: "Times New Roman", serif;">Tasks</span><span style="font-family: "Times New Roman", serif;">同時運作外</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">還需要支援一個</span><span style="font-family: "Times New Roman", serif;">Global Spin-Lock</span><span style="font-family: "Times New Roman", serif;">機制</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">確保同一時間只有一個</span><span style="font-family: "Times New Roman", serif;">Task</span><span style="font-family: "Times New Roman", serif;">在一個需要保護的子系統中運作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">因此</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就有了</span><span style="font-family: "Times New Roman", serif;">BKL</span><span style="font-family: "Times New Roman", serif;">機制的誕生</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">然而</span><span style="font-family: "Times New Roman", serif;">,BKL</span><span style="font-family: "Times New Roman", serif;">機制本身仍有諸多缺陷 </span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">詳情</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">後續會再抽空用其他文章描述多核心的</span><span style="font-family: "Times New Roman", serif;">Kernel</span><span style="font-family: "Times New Roman", serif;">運作</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">也因此</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">新版的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel</span><span style="font-family: "Times New Roman", serif;">會逐步的移除</span><span style="font-family: "Times New Roman", serif;">BKL</span><span style="font-family: "Times New Roman", serif;">機制</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">讓核心可以採用更適當的多核心設計機制</span><span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">參考</span><span style="font-family: "Times New Roman", serif;">Kernel Lock</span><span style="font-family: "Times New Roman", serif;">實作</span><span style="font-family: "Times New Roman", serif;">/lib/kernel_lock.c,BKL</span><span style="font-family: "Times New Roman", serif;">全名為 </span><span style="font-family: "Times New Roman", serif;">Big Kernel Lock,</span><span style="font-family: "Times New Roman", serif;">主要是提供各別子系統</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">確保同一時間只有一個</span><span style="font-family: "Times New Roman", serif;">Task</span><span style="font-family: "Times New Roman", serif;">可以在該子系統中運作</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">例如</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在</span><span style="font-family: "Times New Roman", serif;">Kernel 2.6.31</span><span style="font-family: "Times New Roman", serif;">的</span><span style="font-family: "Times New Roman", serif;">reiserfs</span><span style="font-family: "Times New Roman", serif;">檔案系統實作中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">針對</span><span style="font-family: "Times New Roman", serif;">SMP(Symmetric Multi-Processors)</span><span style="font-family: "Times New Roman", serif;">處理器組態</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">就用到</span><span style="font-family: "Times New Roman", serif;">BKL</span><span style="font-family: "Times New Roman", serif;">確保同一時間只有一個</span><span style="font-family: "Times New Roman", serif;">Task</span><span style="font-family: "Times New Roman", serif;">可以對</span><span style="font-family: "Times New Roman", serif;">reiserfs</span><span style="font-family: "Times New Roman", serif;">進行操作</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">目前</span><span style="font-family: "Times New Roman", serif;">BKL</span><span style="font-family: "Times New Roman", serif;">並不建議在新設計的程式碼中使用</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在最新的</span><span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6.39</span><span style="font-family: "Times New Roman", serif;">中</span><span style="font-family: "Times New Roman", serif;">,BKL</span><span style="font-family: "Times New Roman", serif;">機制也已經移除</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/bkl</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">lock_kernel unlock_kernel</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/bkl/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
</td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">block</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">會把</span><span style="font-family: "Times New Roman", serif;">blk-core (in block/blk-core.c)</span><span style="font-family: "Times New Roman", serif;">中相關處理的動作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">記錄下來</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">供開發者觀察相關行程對</span><span style="font-family: "Times New Roman", serif;">Block</span><span style="font-family: "Times New Roman", serif;">裝置的行為</span><span style="font-family: "Times New Roman", serif;">,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/block</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">block_bio_backmerge block_bio_remap block_rq_insert block_split block_bio_bounce block_getrq block_rq_issue block_unplug_io block_bio_complete block_plug block_rq_remap block_unplug_timer block_bio_frontmerge block_rq_abort block_rq_requeue block_bio_queue block_rq_complete block_sleeprq</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/block/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.102000: block_bio_queue: 253,0 WS 217891064 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.102000: block_bio_remap: 8,2 WS 217891448 + 8 <- (253,0) 217891064</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.102000: block_bio_remap: 8,0 WS 218100293 + 8 <- (8,2) 217891448</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.102000: block_bio_queue: 8,0 WS 218100293 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.102000: block_getrq: 8,0 WS 218100293 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.102000: block_plug: [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.102000: block_rq_insert: 8,0 WS 0 () 218100293 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.102000: block_rq_issue: 8,0 WS 0 () 218100293 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-13394 [000] 5699.114000: block_rq_complete: 8,0 WS () 218100293 + 8 [0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-13394 [000] 5699.114000: block_bio_complete: 253,0 WS 217891064 + 8 [0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.126000: block_bio_queue: 253,0 WS 61864 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.126000: block_bio_remap: 8,2 WS 62248 + 8 <- (253,0) 61864</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.126000: block_bio_remap: 8,0 WS 271093 + 8 <- (8,2) 62248</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.126000: block_bio_queue: 8,0 WS 271093 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.126000: block_getrq: 8,0 WS 271093 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.126000: block_plug: [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.126000: block_rq_insert: 8,0 WS 0 () 271093 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.126000: block_rq_issue: 8,0 WS 0 () 271093 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.127000: block_rq_complete: 8,0 WS () 271093 + 8 [0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.127000: block_bio_complete: 253,0 WS 61864 + 8 [0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.128000: block_bio_queue: 253,0 WS 61872 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.128000: block_bio_remap: 8,2 WS 62256 + 8 <- (253,0) 61872</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.128000: block_bio_remap: 8,0 WS 271101 + 8 <- (8,2) 62256</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.128000: block_bio_queue: 8,0 WS 271101 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.128000: block_getrq: 8,0 WS 271101 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.128000: block_plug: [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.128000: block_rq_insert: 8,0 WS 0 () 271101 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.128000: block_rq_issue: 8,0 WS 0 () 271101 + 8 [kjournald]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.129000: block_rq_complete: 8,0 WS () 271101 + 8 [0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.129000: block_bio_complete: 253,0 WS 61872 + 8 [0]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 5699.129000: block_bio_queue: 253,0 WS 61880 + 8 [kjournald]</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">irq</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/irq</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">irq_handler_entry softirq_entry softirq_raise irq_handler_exit softirq_exit</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/irq/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.436000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.436000: softirq_raise: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.436000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.436000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.436000: softirq_entry: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.436000: softirq_exit: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.437000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.437000: softirq_raise: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.437000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.437000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.437000: softirq_entry: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.437000: softirq_exit: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.438000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.438000: softirq_raise: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.438000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.438000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.438000: softirq_entry: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.438000: softirq_exit: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.439000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.439000: softirq_raise: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.439000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.439000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.439000: softirq_entry: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.439000: softirq_exit: vec=9 [action=RCU]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.440000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.440000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.440000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.441000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.441000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.441000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.442000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.442000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.442000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.443000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.443000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.443000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.444000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.444000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.444000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.445000: softirq_raise: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.445000: softirq_entry: vec=1 [action=TIMER]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 5601.445000: softirq_exit: vec=1 [action=TIMER]</span></span></div>
</td></tr>
<tr class="" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">kmem</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/kmem</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">kmalloc_node mm_page_alloc mm_page_pcpu_drain kmem_cache_alloc mm_page_alloc_extfrag mm_pagevec_free kfree kmem_cache_alloc_node mm_page_alloc_zone_locked kmalloc kmem_cache_free mm_page_free_direct</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/kmem/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.761000: kmem_cache_alloc: call_site=c0527d6e ptr=f4ed5300 bytes_req=192 bytes_alloc=192 gfp_flags=GFP_KERNEL|GFP_ZERO</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_free: call_site=c047fb8b ptr=f59e7740</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_free: call_site=c0527d1b ptr=f4eb3680</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c050c13a ptr=f4f2217c bytes_req=88 bytes_alloc=88 gfp_flags=GFP_KERNEL|GFP_ZERO</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c050c13a ptr=f4f2222c bytes_req=88 bytes_alloc=88 gfp_flags=GFP_KERNEL|GFP_ZERO</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c050be6e ptr=f4f53b1c bytes_req=88 bytes_alloc=88 gfp_flags=GFP_KERNEL|GFP_ZERO</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: mm_page_alloc: page=f7490cc0 pfn=316902 order=0 migratetype=0 gfp_flags=GFP_KERNEL|GFP_REPEAT|GFP_ZERO|0x2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c0511475 ptr=f4f407d0 bytes_req=24 bytes_alloc=24 gfp_flags=GFP_KERNEL</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c05114c5 ptr=f4f58ac8 bytes_req=16 bytes_alloc=16 gfp_flags=GFP_KERNEL</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: mm_page_alloc: page=f7214760 pfn=235451 order=0 migratetype=2 gfp_flags=GFP_HIGHUSER_MOVABLE</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmalloc: call_site=c057c8e7 ptr=f4cc7800 bytes_req=192 bytes_alloc=192 gfp_flags=GFP_KERNEL</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c050c13a ptr=f4f79124 bytes_req=88 bytes_alloc=88 gfp_flags=GFP_KERNEL|GFP_ZERO</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c050af83 ptr=f4f221d4 bytes_req=88 bytes_alloc=88 gfp_flags=GFP_KERNEL</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_free: call_site=c050a063 ptr=f4f221d4</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c050c13a ptr=f4f221d4 bytes_req=88 bytes_alloc=88 gfp_flags=GFP_KERNEL|GFP_ZERO</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: mm_page_alloc: page=f7490c80 pfn=316900 order=0 migratetype=0 gfp_flags=GFP_KERNEL|GFP_REPEAT|GFP_ZERO|0x2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c0511475 ptr=f4edb368 bytes_req=24 bytes_alloc=24 gfp_flags=GFP_KERNEL</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c05114c5 ptr=f4f58438 bytes_req=16 bytes_alloc=16 gfp_flags=GFP_KERNEL</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: mm_page_alloc: page=f7284d80 pfn=249836 order=0 migratetype=2 gfp_flags=GFP_HIGHUSER_MOVABLE</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kfree: call_site=c057cac7 ptr=f4cc7800</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kfree: call_site=c057be25 ptr=f4f517e0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kfree: call_site=c057be2d ptr=f5af3280</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_alloc: call_site=c050baa3 ptr=f4f79f94 bytes_req=88 bytes_alloc=88 gfp_flags=GFP_KERNEL|GFP_ZERO</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: mm_page_alloc: page=f727d7a0 pfn=248893 order=0 migratetype=2 gfp_flags=GFP_HIGHUSER_MOVABLE|GFP_ZERO</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kfree: call_site=c057b030 ptr=f4ee5f40</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kfree: call_site=c052ce9b ptr=f5af3480</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: kmem_cache_free: call_site=c0536936 ptr=f4cdf000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.762000: mm_page_alloc: page=f72571c0 pfn=243982 order=0 migratetype=2 gfp_flags=GFP_HIGHUSER_MOVABLE</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.763000: mm_page_alloc: page=f7490be0 pfn=316895 order=0 migratetype=0 gfp_flags=GFP_KERNEL|GFP_REPEAT|GFP_ZERO|0x2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12884 [000] 5513.763000: mm_page_alloc: page=f7274860 pfn=247747 order=0 migratetype=2 gfp_flags=GFP_HIGHUSER_MOVABLE</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">mce</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/mce</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mce_record</span></div>
</td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">module</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/module</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">module_free module_load module_request module_get module_put</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/module/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">insmod-12522 [000] 5384.763000: module_load: cramfs</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">insmod-12522 [000] 5384.766000: module_put: cramfs call_site=sys_init_module refcnt=2</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">rmmod-12526 [000] 5396.917000: module_free: cramfs</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">napi</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/napi</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">napi_poll</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/napi/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-12085 [000] 5144.521000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-12090 [000] 5144.695000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-12090 [000] 5144.695000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-12099 [000] 5144.895000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-12099 [000] 5144.895000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12102 [000] 5144.969000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12102 [000] 5144.972000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">as-12103 [000] 5145.005000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-12111 [000] 5145.175000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">date-12120 [000] 5145.363000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 5145.366000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">grep-12132 [000] 5145.566000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sh-12136 [000] 5145.631000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 5145.634000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sh-12143 [000] 5145.834000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 5145.855000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sh-12143 [000] 5145.857000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-12147 [000] 5145.915000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-12147 [000] 5145.920000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12152 [000] 5146.053000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cc1-12152 [000] 5146.053000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">as-12153 [000] 5146.113000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-12161 [000] 5146.253000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">sh-12162 [000] 5146.540000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">rm-12168 [000] 5146.543000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-12173 [000] 5146.720000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 5146.724000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ld-12179 [000] 5146.901000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ld-12179 [000] 5146.903000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-12185 [000] 5147.004000: napi_poll: napi poll on napi struct f5981460 for device eth0</span></span></div>
</td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">net</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/net</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">net_dev_queue net_dev_xmit netif_receive_skb netif_rx</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/net/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4446.238000: net_dev_queue: dev=eth0 skbaddr=f5aa2470 len=56</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4446.238000: net_dev_xmit: dev=eth0 skbaddr=f5aa2470 len=56 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.436000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.436000: net_dev_queue: dev=eth0 skbaddr=f5aa2bf0 len=80</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.436000: net_dev_xmit: dev=eth0 skbaddr=f5aa2bf0 len=80 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.593000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4446.596000: net_dev_queue: dev=eth0 skbaddr=f5aa2bf0 len=66</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4446.596000: net_dev_xmit: dev=eth0 skbaddr=f5aa2bf0 len=66 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-9058 [000] 4446.689000: net_dev_queue: dev=eth0 skbaddr=f5aa2470 len=136</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-9058 [000] 4446.689000: net_dev_xmit: dev=eth0 skbaddr=f5aa2470 len=136 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.782000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4446.785000: net_dev_queue: dev=eth0 skbaddr=f5aa2bf0 len=95</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4446.785000: net_dev_xmit: dev=eth0 skbaddr=f5aa2bf0 len=95 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.888000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.888000: net_dev_queue: dev=eth0 skbaddr=f5aa2d70 len=953</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.888000: net_dev_xmit: dev=eth0 skbaddr=f5aa2d70 len=953 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4446.983000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4447.087000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4447.550000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4447.552000: net_dev_queue: dev=eth0 skbaddr=f5aa2d70 len=82</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4447.552000: net_dev_xmit: dev=eth0 skbaddr=f5aa2d70 len=82 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4447.752000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4447.974000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4447.976000: net_dev_queue: dev=eth0 skbaddr=f5aa2d70 len=56</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4447.976000: net_dev_xmit: dev=eth0 skbaddr=f5aa2d70 len=56 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4448.175000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4448.175000: net_dev_queue: dev=eth0 skbaddr=f5aa2bf0 len=1138</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4448.175000: net_dev_xmit: dev=eth0 skbaddr=f5aa2bf0 len=1138 rc=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4448.373000: netif_receive_skb: dev=eth0 skbaddr=f4f6ad40 len=46</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-9058 [000] 4448.701000: net_dev_queue: dev=eth0 skbaddr=f5aa2bf0 len=1004</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-9058 [000] 4448.701000: net_dev_xmit: dev=eth0 skbaddr=f5aa2bf0 len=1004 rc=0</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">power</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/power</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">clock_disable cpu_frequency power_end clock_enable cpu_idle machine_suspend power_frequency clock_set_rate power_domain_target power_start</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/power/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.240000: power_start: type=1 state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.240000: cpu_idle: state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.241000: power_end: cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.241000: cpu_idle: state=4294967295 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.241000: power_start: type=1 state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.241000: cpu_idle: state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.242000: power_end: cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.242000: cpu_idle: state=4294967295 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.242000: power_start: type=1 state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.242000: cpu_idle: state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.243000: power_end: cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.243000: cpu_idle: state=4294967295 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.243000: power_start: type=1 state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.243000: cpu_idle: state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.244000: power_end: cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.244000: cpu_idle: state=4294967295 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.244000: power_start: type=1 state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.244000: cpu_idle: state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.245000: power_end: cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.245000: cpu_idle: state=4294967295 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.245000: power_start: type=1 state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.245000: cpu_idle: state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.246000: power_end: cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.246000: cpu_idle: state=4294967295 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.246000: power_start: type=1 state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.246000: cpu_idle: state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.247000: power_end: cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.247000: cpu_idle: state=4294967295 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.247000: power_start: type=1 state=1 cpu_id=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4370.247000: cpu_idle: state=1 cpu_id=0</span></span></div>
</td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">raw_syscalls</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/raw_syscalls</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter sys_exit</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/raw_syscalls/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897945: sys_enter: NR 63 (a, 1, a, 0, a, bff53448)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897966: sys_exit: NR 63 = 1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897970: sys_enter: NR 221 (a, 1, 0, 0, b77cfff4, bff53328)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897972: sys_exit: NR 221 = 1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897975: sys_enter: NR 6 (a, 1, 0, 0, 0, bff53448)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897976: sys_exit: NR 6 = 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897988: sys_enter: NR 175 (0, 0, 80fe4dc, 8,b77cfff4, bff535bc)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897991: sys_exit: NR 175 = 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897994: sys_enter: NR 174 (2, bff53400, bff53374, 8, b77cfff4, bff53498)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-3798 [000] 9209.897996: sys_exit: NR 174 = 0</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="20" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">sched</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/sched</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sched_process_exit sched_stat_sleep sched_process_fork sched_stat_wait sched_kthread_stop sched_process_free sched_switch sched_kthread_stop_ret sched_process_wait sched_wait_task sched_migrate_task sched_stat_iowait sched_wakeup sched_pi_setprio sched_stat_runtime sched_wakeup_new</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/sched/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 4232.264000: sched_stat_wait: comm=kworker/0:0 pid=4 delay=0 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 4232.264000: sched_switch: prev_comm=bash prev_pid=1957 prev_prio=120 prev_state=R ==> next_comm=kworker/0:0 next_pid=4 next_prio=120</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.265000: sched_stat_runtime: comm=kworker/0:0 pid=4 runtime=956546 [ns] vruntime=1353114806115 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.265000: sched_stat_sleep: comm=in.telnetd pid=1955 delay=3893232 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.265000: sched_wakeup: comm=in.telnetd pid=1955 prio=120 success=1 target_cpu=000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.265000: sched_stat_wait: comm=in.telnetd pid=1955 delay=0 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.265000: sched_switch: prev_comm=kworker/0:0 prev_pid=4 prev_prio=120 prev_state=S ==> next_comm=in.telnetd next_pid=1955 next_prio=120</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4232.265000: sched_stat_wait: comm=bash pid=1957 delay=956546 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4232.265000: sched_switch: prev_comm=in.telnetd prev_pid=1955 prev_prio=120 prev_state=S ==> next_comm=bash next_pid=1957 next_prio=120</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 4232.266000: sched_stat_runtime: comm=bash pid=1957 runtime=1329219 [ns] vruntime=1353118178788 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 4232.267000: sched_stat_runtime: comm=bash pid=1957 runtime=672432 [ns] vruntime=1353118851220 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 4232.267000: sched_wakeup: comm=bash pid=1957 prio=120 success=0 target_cpu=000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 4232.267000: sched_switch: prev_comm=bash prev_pid=1957 prev_prio=120 prev_state=S ==> next_comm=swapper next_pid=0 next_prio=120</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4232.268000: sched_stat_sleep: comm=kworker/0:0 pid=4 delay=3016584 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4232.268000: sched_wakeup: comm=kworker/0:0 pid=4 prio=120 success=1 target_cpu=000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4232.268000: sched_stat_wait: comm=kworker/0:0 pid=4 delay=0 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4232.268000: sched_switch: prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/0:0 next_pid=4 next_prio=120</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.268000: sched_stat_sleep: comm=in.telnetd pid=1955 delay=3016584 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.268000: sched_wakeup: comm=in.telnetd pid=1955 prio=120 success=1 target_cpu=000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.268000: sched_stat_wait: comm=in.telnetd pid=1955 delay=0 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 4232.268000: sched_switch: prev_comm=kworker/0:0 prev_pid=4 prev_prio=120 prev_state=S ==> next_comm=in.telnetd next_pid=1955 next_prio=120</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 4232.268000: sched_switch: prev_comm=in.telnetd prev_pid=1955 prev_prio=120 prev_state=S ==> next_comm=swapper next_pid=0 next_prio=120</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4232.533000: sched_stat_sleep: comm=top pid=9088 delay=2003729805 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4232.533000: sched_wakeup: comm=top pid=9088 prio=120 success=1 target_cpu=000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4232.533000: sched_stat_wait: comm=top pid=9088 delay=292215 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 4232.533000: sched_switch: prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=top next_pid=9088 next_prio=120</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9088 [000] 4232.533000: sched_stat_sleep: comm=in.telnetd pid=9058 delay=2005198147 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9088 [000] 4232.533000: sched_wakeup: comm=in.telnetd pid=9058 prio=120 success=1 target_cpu=000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9088 [000] 4232.534000: sched_stat_runtime: comm=top pid=9088 runtime=889219 [ns] vruntime=1353116740439 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9088 [000] 4232.535000: sched_stat_runtime: comm=top pid=9088 runtime=872178 [ns] vruntime=1353117612617 [ns]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9088 [000] 4232.536000: sched_stat_runtime: comm=top pid=9088 runtime=1030578 [ns] vruntime=1353118643195 [ns]</span></span></div>
</td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">scsi</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/scsi</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">scsi_dispatch_cmd_done scsi_dispatch_cmd_start scsi_eh_wakeup scsi_dispatch_cmd_error scsi_dispatch_cmd_timeout</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/scsi/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.730000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=218489949 txlen=8 protect=0 raw=2a 00 0d 05 e4 5d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-10718 [000] 4120.730000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=218489949 txlen=8 protect=0 raw=2a 00 0d 05 e4 5d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.734000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267293 txlen=8 protect=0 raw=2a 00 00 04 14 1d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.734000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267293 txlen=8 protect=0 raw=2a 00 00 04 14 1d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.734000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267301 txlen=8 protect=0 raw=2a 00 00 04 14 25 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.734000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267301 txlen=8 protect=0 raw=2a 00 00 04 14 25 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.735000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267309 txlen=8 protect=0 raw=2a 00 00 04 14 2d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.735000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267309 txlen=8 protect=0 raw=2a 00 00 04 14 2d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.736000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267317 txlen=8 protect=0 raw=2a 00 00 04 14 35 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.736000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267317 txlen=8 protect=0 raw=2a 00 00 04 14 35 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.736000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267325 txlen=8 protect=0 raw=2a 00 00 04 14 3d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.736000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267325 txlen=8 protect=0 raw=2a 00 00 04 14 3d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.738000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267333 txlen=8 protect=0 raw=2a 00 00 04 14 45 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.738000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267333 txlen=8 protect=0 raw=2a 00 00 04 14 45 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.738000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267341 txlen=8 protect=0 raw=2a 00 00 04 14 4d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.738000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267341 txlen=8 protect=0 raw=2a 00 00 04 14 4d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.738000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267349 txlen=8 protect=0 raw=2a 00 00 04 14 55 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.738000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267349 txlen=8 protect=0 raw=2a 00 00 04 14 55 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.742000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267357 txlen=8 protect=0 raw=2a 00 00 04 14 5d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.742000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267357 txlen=8 protect=0 raw=2a 00 00 04 14 5d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.742000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267365 txlen=8 protect=0 raw=2a 00 00 04 14 65 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.742000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267365 txlen=8 protect=0 raw=2a 00 00 04 14 65 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.743000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267373 txlen=8 protect=0 raw=2a 00 00 04 14 6d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.743000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267373 txlen=8 protect=0 raw=2a 00 00 04 14 6d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.744000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267381 txlen=8 protect=0 raw=2a 00 00 04 14 75 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.744000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267381 txlen=8 protect=0 raw=2a 00 00 04 14 75 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.744000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267389 txlen=8 protect=0 raw=2a 00 00 04 14 7d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.744000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267389 txlen=8 protect=0 raw=2a 00 00 04 14 7d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.745000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267397 txlen=8 protect=0 raw=2a 00 00 04 14 85 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.745000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267397 txlen=8 protect=0 raw=2a 00 00 04 14 85 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.745000: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267405 txlen=8 protect=0 raw=2a 00 00 04 14 8d 00 00 08 00)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kjournald-48 [000] 4120.745000: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 data_sgl=1 prot_sgl=0 cmnd=(WRITE_10 lba=267405 txlen=8 protect=0 raw=2a 00 00 04 14 8d 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">signal</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/signal</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">signal_deliver signal_lose_info signal_generate signal_overflow_fail</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/signal/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9862 [000] 3893.720000: signal_generate: sig=17 errno=0 code=262145 comm=bash pid=1957</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9863 [000] 3893.732000: signal_generate: sig=17 errno=0 code=262145 comm=bash pid=1957</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3893.733000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=807aa60 sa_flags=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9864 [000] 3894.941000: signal_generate: sig=17 errno=0 code=262145 comm=bash pid=1957</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9865 [000] 3894.949000: signal_generate: sig=17 errno=0 code=262145 comm=bash pid=1957</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3894.949000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=807aa60 sa_flags=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9868 [000] 3899.215000: signal_generate: sig=17 errno=0 code=262145 comm=sh pid=9867</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9869 [000] 3899.225000: signal_generate: sig=17 errno=0 code=262145 comm=sh pid=9867</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9867 [000] 3899.226000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=807aa60 sa_flags=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9867 [000] 3899.228000: signal_generate: sig=17 errno=0 code=262145 comm=make pid=9866</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-9866 [000] 3899.228000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=8053850 sa_flags=10000000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9870 [000] 3899.245000: signal_generate: sig=17 errno=0 code=262145 comm=make pid=9866</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-9866 [000] 3899.246000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=8053850 sa_flags=10000000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9873 [000] 3899.336000: signal_generate: sig=17 errno=0 code=262145 comm=arm-none-eabi-g pid=9872</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9874 [000] 3899.412000: signal_generate: sig=17 errno=0 code=262145 comm=arm-none-eabi-g pid=9872</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9872 [000] 3899.414000: signal_generate: sig=17 errno=0 code=262145 comm=sh pid=9871</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9871 [000] 3899.414000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=807aa60 sa_flags=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9875 [000] 3899.428000: signal_generate: sig=17 errno=0 code=262145 comm=sh pid=9871</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9871 [000] 3899.428000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=807aa60 sa_flags=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9871 [000] 3899.431000: signal_generate: sig=17 errno=0 code=262145 comm=make pid=9866</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-9866 [000] 3899.431000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=8053850 sa_flags=10000000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9878 [000] 3899.514000: signal_generate: sig=17 errno=0 code=262145 comm=arm-none-eabi-g pid=9877</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9879 [000] 3899.578000: signal_generate: sig=17 errno=0 code=262145 comm=arm-none-eabi-g pid=9877</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9877 [000] 3899.580000: signal_generate: sig=17 errno=0 code=262145 comm=sh pid=9876</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9876 [000] 3899.580000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=807aa60 sa_flags=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9880 [000] 3899.593000: signal_generate: sig=17 errno=0 code=262145 comm=sh pid=9876</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9876 [000] 3899.594000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=807aa60 sa_flags=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9876 [000] 3899.595000: signal_generate: sig=17 errno=0 code=262145 comm=make pid=9866</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">make-9866 [000] 3899.595000: signal_deliver: sig=17 errno=0 code=262145 sa_handler=8053850 sa_flags=10000000</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-9883 [000] 3899.682000: signal_generate: sig=17 errno=0 code=262145 comm=arm-none-eabi-g pid=9882</span></span></div>
</td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">skb</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/skb</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">consume_skb kfree_skb skb_copy_datagram_iovec</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/skb/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3800.664000: consume_skb: skbaddr=f5aa2ef0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3800.864000: consume_skb: skbaddr=f5aa2a70</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 3801.184000: consume_skb: skbaddr=f5aa2a70</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3801.281000: skb_copy_datagram_iovec: skbaddr=f4f6a500 len=3</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3801.285000: consume_skb: skbaddr=f5aa2ef0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3801.437000: skb_copy_datagram_iovec: skbaddr=f4f6a500 len=3</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3801.440000: consume_skb: skbaddr=f5aa2ef0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3802.094000: skb_copy_datagram_iovec: skbaddr=f4f6a500 len=3</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3802.098000: consume_skb: skbaddr=f5aa2ef0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3802.605000: skb_copy_datagram_iovec: skbaddr=f4f6a500 len=1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3802.607000: kfree_skb: skbaddr=f4f6a500 protocol=0 location=c0814f61</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3802.609000: consume_skb: skbaddr=f5aa2ef0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3802.804000: consume_skb: skbaddr=f5aa2a70</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 3803.193000: consume_skb: skbaddr=f5aa2a70</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3803.392000: consume_skb: skbaddr=f5aa2ef0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 3805.206000: consume_skb: skbaddr=f5aa2ef0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 3805.211000: consume_skb: skbaddr=f5aa2a70</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 3805.212000: consume_skb: skbaddr=f5aa22f0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3805.970000: skb_copy_datagram_iovec: skbaddr=f4f6a500 len=3</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3805.974000: consume_skb: skbaddr=f5aa22f0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3806.251000: skb_copy_datagram_iovec: skbaddr=f4f6a500 len=1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3806.252000: kfree_skb: skbaddr=f4f6a500 protocol=0 location=c0814f61</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3806.255000: consume_skb: skbaddr=f5aa22f0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3806.457000: consume_skb: skbaddr=f5aa2a70</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 3807.222000: consume_skb: skbaddr=f5aa2a70</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 3807.222000: consume_skb: skbaddr=f5aa22f0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">top-9088 [000] 3807.223000: consume_skb: skbaddr=f5aa22f0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3807.300000: skb_copy_datagram_iovec: skbaddr=f4f6a500 len=1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">more-9857 [000] 3807.303000: consume_skb: skbaddr=f5aa2ef0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3807.431000: consume_skb: skbaddr=f5aa2a70</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3807.471000: consume_skb: skbaddr=f5aa2770</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1955 [000] 3807.471000: skb_copy_datagram_iovec: skbaddr=f4f6a500 len=3</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">syscalls</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/syscalls</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_accept</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_accept4</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_access</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_acct</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_add_key</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_adjtimex</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_alarm</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_bdflush</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_bind</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_enter_brk</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_exit_vmsplice</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_exit_wait4</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_exit_waitid</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_exit_waitpid</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_exit_write</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">sys_exit_writev</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/syscalls/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_open -> 0x3</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_fcntl64(fd: 1, cmd: 1, arg: 0)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_fcntl64 -> 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_fcntl64(fd: 1, cmd: 0, arg: a)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_fcntl64 -> 0xa</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_fcntl64(fd: 1, cmd: 1, arg: 0)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_fcntl64 -> 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_fcntl64(fd: a, cmd: 2, arg: 1)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_fcntl64 -> 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_dup2(oldfd: 3, newfd: 1)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_dup2 -> 0x1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_close(fd: 3)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.573000: sys_close -> 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_write(fd: 1, buf: b781c000, count: 1)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_write -> 0x1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_dup2(oldfd: a, newfd: 1)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_dup2 -> 0x1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_fcntl64(fd: a, cmd: 1, arg: 0)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_fcntl64 -> 0x1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_close(fd: a)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_close -> 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_rt_sigprocmask(how: 0, set: 0, oset: 80fe4dc, sigsetsize: 8)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_rt_sigprocmask -> 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_rt_sigaction(sig: 2, act: bfd40dc0, oact: bfd40d34, sigsetsize: 8)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_rt_sigaction -> 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_time(tloc: 0)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_time -> 0x4dd7d442</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_rt_sigprocmask(how: 0, set: bfd4054c, oset: bfd404cc, sigsetsize: 8)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_rt_sigprocmask -> 0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_ioctl(fd: ff, cmd: 5410, arg: bfd404c4)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3716.574000: sys_ioctl -> 0x0</span></span></div>
</td></tr>
<tr valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">timer</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/timer</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">hrtimer_expire_exit itimer_state timer_init hrtimer_init timer_cancel timer_start hrtimer_cancel hrtimer_start timer_expire_entry hrtimer_expire_entry itimer_expire timer_expire_exit</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/timer/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1925 [000] 3590.212000: timer_cancel: timer=f58a10cc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1925 [000] 3590.213000: timer_expire_entry: timer=f58a10cc function=delayed_work_timer_fn now=3290213</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1925 [000] 3590.213000: timer_expire_exit: timer=f58a10cc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">in.telnetd-1923 [000] 3590.213000: timer_start: timer=f5446b4c function=tcp_write_timer expires=3290566 [timeout=353]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1925 [000] 3590.215000: timer_start: timer=f58a10cc function=delayed_work_timer_fn expires=3290216 [timeout=1]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.216000: timer_cancel: timer=f58a10cc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.216000: timer_expire_entry: timer=f58a10cc function=delayed_work_timer_fn now=3290216</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.216000: timer_expire_exit: timer=f58a10cc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.275000: timer_cancel: timer=f5446b68</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.275000: timer_expire_entry: timer=f5446b68 function=tcp_delack_timer now=3290275</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.275000: timer_expire_exit: timer=f5446b68</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.409000: timer_cancel: timer=f5446b4c</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.409000: timer_start: timer=f5446b4c function=tcp_write_timer expires=3290767 [timeout=358]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.458000: hrtimer_cancel: hrtimer=f4d21b80</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.458000: hrtimer_expire_entry: hrtimer=f4d21b80 function=hrtimer_wakeup now=3612200721124</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.458000: hrtimer_expire_exit: hrtimer=f4d21b80</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_server-1890 [000] 3590.459000: hrtimer_init: hrtimer=f4d21b80 clockid=CLOCK_MONOTONIC mode=HRTIMER_MODE_ABS</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">gam_server-1890 [000] 3590.459000: hrtimer_start: hrtimer=f4d21b80 function=hrtimer_wakeup expires=3613207309303 softexpires=3613202309315</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.767000: timer_cancel: timer=f5446b4c</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.767000: timer_expire_entry: timer=f5446b4c function=tcp_write_timer now=3290767</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3590.767000: timer_expire_exit: timer=f5446b4c</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3591.002000: timer_cancel: timer=f64036b0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3591.002000: timer_expire_entry: timer=f64036b0 function=delayed_work_timer_fn now=3291002</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3591.002000: timer_expire_exit: timer=f64036b0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3591.002000: timer_start: timer=f64036b0 function=delayed_work_timer_fn expires=3292002 [timeout=1000]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3591.004000: timer_cancel: timer=f598135c</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3591.004000: timer_expire_entry: timer=f598135c function=e1000_watchdog now=3291004</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3591.004000: timer_start: timer=f598135c function=e1000_watchdog expires=3293004 [timeout=2000]</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">vmscan</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/vmscan</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mm_vmscan_memcg_isolate mm_vmscan_memcg_reclaim_begin mm_vmscan_direct_reclaim_begin mm_vmscan_memcg_reclaim_end mm_vmscan_direct_reclaim_end mm_vmscan_memcg_softlimit_reclaim_begin mm_vmscan_kswapd_sleep mm_vmscan_memcg_softlimit_reclaim_end mm_vmscan_kswapd_wake mm_vmscan_wakeup_kswapd mm_vmscan_lru_isolate mm_vmscan_writepage mm_vmscan_lru_shrink_inactive</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/vmscan/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
</td></tr>
<tr class="" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">workqueue</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/workqueue</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">workqueue_activate_work workqueue_execute_start workqueue_execute_end workqueue_queue_work</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/workqueue/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">/debug/tracing/trace</span><span style="font-family: "Times New Roman", serif;">下的結果</span><span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3205.721000: workqueue_queue_work: work struct=f58a24bc function=flush_to_ldisc workqueue=f600dac0 req_cpu=0 cpu=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">bash-1957 [000] 3205.721000: workqueue_activate_work: work struct f58a24bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3205.721000: workqueue_execute_start: work struct f58a24bc: function flush_to_ldisc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3205.721000: workqueue_execute_end: work struct f58a24bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3205.723000: workqueue_queue_work: work struct=f58a24bc function=flush_to_ldisc workqueue=f600dac0 req_cpu=0 cpu=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3205.723000: workqueue_activate_work: work struct f58a24bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3205.723000: workqueue_execute_start: work struct f58a24bc: function flush_to_ldisc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3205.723000: workqueue_execute_end: work struct f58a24bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3206.002000: workqueue_queue_work: work struct=f64036a0 function=vmstat_update workqueue=f600dac0 req_cpu=0 cpu=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3206.002000: workqueue_activate_work: work struct f64036a0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3206.002000: workqueue_execute_start: work struct f64036a0: function vmstat_update</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3206.002000: workqueue_execute_end: work struct f64036a0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3206.347000: workqueue_queue_work: work struct=f58bf8bc function=flush_to_ldisc workqueue=f600dac0 req_cpu=0 cpu=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3206.347000: workqueue_activate_work: work struct f58bf8bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3206.347000: workqueue_execute_start: work struct f58bf8bc: function flush_to_ldisc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3206.347000: workqueue_execute_end: work struct f58bf8bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3206.349000: workqueue_queue_work: work struct=f58a24bc function=flush_to_ldisc workqueue=f600dac0 req_cpu=0 cpu=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3206.349000: workqueue_activate_work: work struct f58a24bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3206.349000: workqueue_execute_start: work struct f58a24bc: function flush_to_ldisc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3206.349000: workqueue_execute_end: work struct f58a24bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3206.654000: workqueue_queue_work: work struct=f58bf8bc function=flush_to_ldisc workqueue=f600dac0 req_cpu=0 cpu=0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><idle>-0 [000] 3206.654000: workqueue_activate_work: work struct f58bf8bc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3206.654000: workqueue_execute_start: work struct f58bf8bc: function flush_to_ldisc</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">kworker/0:0-4 [000] 3206.654000: workqueue_execute_end: work struct f58bf8bc</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">writeback</span></td><td style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="419"><span style="font-family: "Times New Roman", serif;">檢視 </span><span style="font-family: "Times New Roman", serif;">events/writeback</span><span style="font-family: "Times New Roman", serif;">目錄下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">共支援以下的</span><span style="font-family: "Times New Roman", serif;">Events</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">writeback_exec writeback_nothread wbc_balance_dirty_start writeback_nowork wbc_balance_dirty_wait writeback_pages_written wbc_balance_dirty_written writeback_queue wbc_writeback_start writeback_thread_start wbc_writeback_wait writeback_thread_stop wbc_writeback_written writeback_wait_iff_congested wbc_writepage writeback_wake_background writeback_bdi_register writeback_wake_forker_thread writeback_bdi_unregister writeback_wake_thread writeback_congestion_wait</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">#echo 1 > /debug/tracing/events/writeback/enable</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">檢視 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">/debug/tracing/trace</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">下的結果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">,</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># tracer: nop</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">#</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># TASK-PID CPU# TIMESTAMP FUNCTION</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"># | | | | |</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-2719 [000] 2262.160000: writeback_wake_thread: bdi 253:0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2262.160000: wbc_writeback_start: bdi 253:0: towrt=1024 skip=0 mode=0 kupd=1 bgrd=0 reclm=0 cyclic=1 more=0 older=0x1d7b80 start=0x0 end=0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2262.160000: wbc_writeback_written: bdi 253:0: towrt=1024 skip=0 mode=0 kupd=1 bgrd=0 reclm=0 cyclic=1 more=0 older=0x1d7b80 start=0x0 end=0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2262.160000: writeback_pages_written: 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2267.160000: wbc_writeback_start: bdi 253:0: towrt=1024 skip=0 mode=0 kupd=1 bgrd=0 reclm=0 cyclic=1 more=0 older=0x1d8f08 start=0x0 end=0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2267.160000: wbc_writeback_written: bdi 253:0: towrt=1024 skip=0 mode=0 kupd=1 bgrd=0 reclm=0 cyclic=1 more=0 older=0x1d8f08 start=0x0 end=0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2267.160000: writeback_pages_written: 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2272.160000: wbc_writeback_start: bdi 253:0: towrt=1024 skip=0 mode=0 kupd=1 bgrd=0 reclm=0 cyclic=1 more=0 older=0x1da290 start=0x0 end=0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2272.160000: writeback_pages_written: 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2277.160000: wbc_writeback_start: bdi 253:0: towrt=1024 skip=0 mode=0 kupd=1 bgrd=0 reclm=0 cyclic=1 more=0 older=0x1db618 start=0x0 end=0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2277.160000: wbc_writeback_written: bdi 253:0: towrt=1024 skip=0 mode=0 kupd=1 bgrd=0 reclm=0 cyclic=1 more=0 older=0x1db618 start=0x0 end=0x0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2277.160000: writeback_pages_written: 0</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><…>-1921 [000] 2282.160000: wbc_writeback_start: bdi 253:0: towrt=1024 skip=0 mode=0 kupd=1 bgrd=0 reclm=0 cyclic=1 more=0 older=0x1dc9a0 start=0x0 end=0x0</span></span></div>
</td></tr>
</tbody></table>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="524"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>結尾</strong></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>,</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;">在平台移植與開發上</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">效能調教對於產品化的影響很深</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">本文主要介紹</span><span style="font-family: "Times New Roman", serif;">Ftrace</span><span style="font-family: "Times New Roman", serif;">的概念與操作範例</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">對筆者而言</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">這套工具可以幫助在複雜行為下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">去分析系統效能的瓶頸</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">例如</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">是否有中斷關閉過長的行為</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">或是修改過的核心函式</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">不適當的行為佔據過多的處理器時間</span><span style="font-family: "Times New Roman", serif;">. </span><span style="font-family: "Times New Roman", serif;">目前</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">在</span><span style="font-family: "Times New Roman", serif;">Linux</span><span style="font-family: "Times New Roman", serif;">平台上</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">能使用的工具不少</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: "Times New Roman", serif;">或是也可以使用商業的</span><span style="font-family: "Times New Roman", serif;">ICE</span><span style="font-family: "Times New Roman", serif;">產品</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Times New Roman", serif;">對這些工具內部運作原理掌握的程度越高</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">我們就會有足夠的知識背景幫助團隊在問題發生時</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">借重適當的工具去分析問題的原因</span><span style="font-family: "Times New Roman", serif;">,Ftrace</span><span style="font-family: "Times New Roman", serif;">只是提供系統問題一部分的資訊</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">其它可用的工具與分析問題的知識背景</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">會是有志於在這產業的開發者</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Times New Roman", serif;">需要持續努力的</span><span style="font-family: "Times New Roman", serif;">.</span></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-13669335933611936722017-06-01T09:56:00.002-07:002017-06-01T09:56:41.933-07:00Android筆記 – 從DEX檔案格式看Dalvik的運作<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android筆記 – 從DEX檔案格式看Dalvik的運作</h1>
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Android</strong></span></span><span style="font-size: small;"><strong>筆記 </strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>– </strong></span></span><span style="font-size: small;"><strong>從</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>DEX</strong></span></span><span style="font-size: small;"><strong>檔案</strong></span><span style="font-size: small;"><strong>格式看</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Dalvik</strong></span></span><span style="font-size: small;"><strong>的運作</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial, sans-serif;"><span style="font-size: xx-small;">hlchou@mail2000.com.tw<br />by loda</span></span><span style="font-size: small;"><strong></strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
記得剛投入系統軟體領域時<span style="font-family: "Times New Roman", serif;">,</span>透過一些文章(當年<span style="font-family: "Times New Roman", serif;">Microsoft Systems Journal</span>算是很補的技術雜誌<span style="font-family: "Times New Roman", serif;">.),</span>知道<span style="font-family: "Times New Roman", serif;">DOS</span>的<span style="font-family: "Times New Roman", serif;">MZ(</span>以<span style="font-family: "Times New Roman", serif;">DOS</span>開發者 <span style="font-family: "Times New Roman", serif;">Mark Zbikowski</span>的縮寫命名<span style="font-family: "Times New Roman", serif;">)</span>檔案格式<span style="font-family: "Times New Roman", serif;">,</span>也藉此了解在<span style="font-family: "Times New Roman", serif;">DOS</span>時代使用<span style="font-family: "Times New Roman", serif;">Memory Segment</span>與<span style="font-family: "Times New Roman", serif;">.com</span>跟<span style="font-family: "Times New Roman", serif;">.exe</span>檔案的差異<span style="font-family: "Times New Roman", serif;">,</span>隨後<span style="font-family: "Times New Roman", serif;">,Windows 3.1</span>推出<span style="font-family: "Times New Roman", serif;">,NE(New Executable) </span>執行檔<span style="font-family: "Times New Roman", serif;">,VxD LE( Linear Executable)</span>驅動程式與之後的<span style="font-family: "Times New Roman", serif;">Windows 9x/ME/NT/2000/XP </span>的<span style="font-family: "Times New Roman", serif;">PE(Portable Executable)</span>檔案格式<span style="font-family: "Times New Roman", serif;">,</span>是有志於了解動態函式庫<span style="font-family: "Times New Roman", serif;">DLL,Windows</span>應用與核心跟反組譯<span style="font-family: "Times New Roman", serif;">Hacking</span>時<span style="font-family: "Times New Roman", serif;">,</span>所必備的基礎知識<span style="font-family: "Times New Roman", serif;">. </span>到了<span style="font-family: "Times New Roman", serif;">Linux/Unix</span>的環境時<span style="font-family: "Times New Roman", serif;">,ELF(Executable and Linkable Format) </span>也是從事開發前<span style="font-family: "Times New Roman", serif;">,</span>從反組譯工具<span style="font-family: "Times New Roman", serif;">,</span>到了解系統運作時<span style="font-family: "Times New Roman", serif;">,</span>可以深化系統觀點的知識背景<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>也因此<span style="font-family: "Times New Roman", serif;">,</span>在開發<span style="font-family: "Times New Roman", serif;">Android</span>相關產品時<span style="font-family: "Times New Roman", serif;">,</span>了解<span style="font-family: "Times New Roman", serif;">Dalvik DEX</span>檔案格式<span style="font-family: "Times New Roman", serif;">,</span>也應是個值得深入探究的資訊<span style="font-family: "Times New Roman", serif;">,</span>並藉此了解在<span style="font-family: "Times New Roman", serif;">Dalvik</span>系統的底層與檔案格式中<span style="font-family: "Times New Roman", serif;">,</span>所提供的資訊<span style="font-family: "Times New Roman", serif;">,</span>在評估系統改善項目時<span style="font-family: "Times New Roman", serif;">,</span>這些資訊就能幫助我們有足夠的背景做出適當的判斷與設計建議<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>同樣的<span style="font-family: "Times New Roman", serif;">,</span>筆者會盡力確保所提供的訊息正確性<span style="font-family: "Times New Roman", serif;">,</span>然可能因為<span style="font-family: "Times New Roman", serif;">Android</span>本身的改版<span style="font-family: "Times New Roman", serif;">,</span>與筆者有限的知識<span style="font-family: "Times New Roman", serif;">,</span>若有不盡完美之處<span style="font-family: "Times New Roman", serif;">,</span>也歡迎給予指教<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="color: black;"></span></span></span><span style="color: navy;"><span style="color: black;">關心</span><span style="font-family: "Times New Roman", serif;"><span style="color: black;">Android</span></span></span><span style="color: navy;"><span style="color: black;">發展的人</span><span style="font-family: "Times New Roman", serif;"><span style="color: black;">,</span></span></span><span style="color: navy;"><span style="color: black;">也可以透過這個連結</span></span><span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://code.google.com/p/android/issues/list" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://code.google.com/p/android/issues/list#</a></span></span> </span>了解目前相關<span style="font-family: "Times New Roman", serif;">Issue</span>的狀況<span style="font-family: "Times New Roman", serif;">,</span>同時<span style="font-family: "Times New Roman", serif;">,</span>也推薦一個很不錯的 <span style="font-family: "Times New Roman", serif;">Dalvik Talk “Android: Dalvik VM Internals — Google 2008 </span>台北程式開發日<span style="font-family: "Times New Roman", serif;">” ,</span>講者為程本中<span style="font-family: "Times New Roman", serif;">,</span>目前是<span style="font-family: "Times New Roman", serif;">Android</span>團隊的一員<span style="font-family: "Times New Roman", serif;">,Youtube</span>網址是在<span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://www.youtube.com/watch?v=FsNKIo4bIro&feature=player_embedded#at=26" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.youtube.com/watch?v=FsNKIo4bIro&feature=player_embedded#at=26</a></span></span> .</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>透過<span style="font-family: "Times New Roman", serif;">DEX</span>檔案格式的支援<span style="font-family: "Times New Roman", serif;">,</span>相比過去的作法<span style="font-family: "Times New Roman", serif;">,</span>筆者認為可以有如下的好處</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1, </span>同類型的<span style="font-family: "Times New Roman", serif;">String (</span>例如<span style="font-family: "Times New Roman", serif;">: lang/…/string)</span>可以只存在一份<span style="font-family: "Times New Roman", serif;">,</span>然後透過 <span style="font-family: "Times New Roman", serif;">Index</span>對應<span style="font-family: "Times New Roman", serif;">,</span>節省為數可觀的儲存空間</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2, </span>可以把屬於同一個應用的<span style="font-family: "Times New Roman", serif;">Class</span>檔案<span style="font-family: "Times New Roman", serif;">,</span>整合在同一個<span style="font-family: "Times New Roman", serif;">DEX</span>檔案中<span style="font-family: "Times New Roman", serif;">,</span>有利於儲存空間與個別應用的管理</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3, </span>支援<span style="font-family: "Times New Roman", serif;">Optimized DEX</span>格式<span style="font-family: "Times New Roman", serif;">,</span>只要曾在載入或是安裝時執行過最佳化流程<span style="font-family: "Times New Roman", serif;">,</span>就可以保留該次的結果<span style="font-family: "Times New Roman", serif;">,</span>加速下一次的執行<span style="font-family: "Times New Roman", serif;">. (</span>只限於驗證與最佳化<span style="font-family: "Times New Roman", serif;">, JIT</span>每次只要重新啟動就會重新執行<span style="font-family: "Times New Roman", serif;">)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>一個經過優化過的<span style="font-family: "Times New Roman", serif;">DEX</span>檔案<span style="font-family: "Times New Roman", serif;">,</span>前面會加上<span style="font-family: "Times New Roman", serif;">40bytes</span>的<span style="font-family: "Times New Roman", serif;">ODEX</span>檔頭<span style="font-family: "Times New Roman", serif;">,</span>格式如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="font-size: xx-small;">typedef</span></span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="font-size: xx-small;">struct</span></span><span style="font-size: xx-small;"> DexOptHeader {</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u1 magic[8]; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* includes version number */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 dexOffset; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* file offset of DEX header */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 dexLength;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 depsOffset; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* offset of optimized DEX dependency table */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 depsLength;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 optOffset; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* file offset of optimized data tables */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 optLength;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 flags; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* some info flags */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 checksum; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* adler32 checksum covering deps/opt */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: green;"><span style="font-size: xx-small;">/* pad for 64-bit alignment if necessary */</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">} DexOptHeader;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>我們可以透過辨認前面的<span style="font-family: "Times New Roman", serif;">Magic Code</span>(例如用<span style="font-family: "Times New Roman", serif;">UltraEdit</span>打開<span style="font-family: "Times New Roman", serif;">DEX</span>檔案查看前<span style="font-family: "Times New Roman", serif;">8bytes)</span>是否為 <span style="font-family: "Times New Roman", serif;">“dey\n036\0″,</span>確認<span style="font-family: "Times New Roman", serif;">DEX</span>檔案是否已經被最佳化過<span style="font-family: "Times New Roman", serif;">.</span>而沒有被優化過的<span style="font-family: "Times New Roman", serif;">DEX </span>檔案檔頭<span style="font-family: "Times New Roman", serif;">Magic Code</span>會直接就是 <span style="font-family: "Times New Roman", serif;">“dex\n035\0″,</span>可供相關的<span style="font-family: "Times New Roman", serif;">DEX</span>檔案處理機制判斷<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>基本的 <span style="font-family: "Times New Roman", serif;">DEX</span>檔頭如下所示<span style="font-family: "Times New Roman", serif;">,</span>大小為<span style="font-family: "Times New Roman", serif;">112bytes.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="font-size: xx-small;">typedef</span></span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="font-size: xx-small;">struct</span></span><span style="font-size: xx-small;"> DexHeader {</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u1 magic[8]; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* includes version number */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 checksum; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* adler32 checksum */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u1 signature[kSHA1DigestLen]; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* SHA-1 hash */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 fileSize; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* length of entire file */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 headerSize; </span></span><span style="color: green;"><span style="font-size: xx-small;">/* offset to start of next section */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 endianTag;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 linkSize;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 linkOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 mapOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 stringIdsSize;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 stringIdsOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 typeIdsSize;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 typeIdsOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 protoIdsSize;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 protoIdsOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 fieldIdsSize;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 fieldIdsOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 methodIdsSize;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 methodIdsOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 classDefsSize;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 classDefsOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 dataSize;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">u4 dataOff;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">} DexHeader;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>接下來就讓我們基於這些檔案欄位<span style="font-family: "Times New Roman", serif;">,</span>進一步的加以說明<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>計算</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Dex Checksum</strong></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Dex</span>驗證<span style="font-family: "Times New Roman", serif;">Checksum</span>時<span style="font-family: "Times New Roman", serif;">,</span>如果該檔案已經被最佳化處理過<span style="font-family: "Times New Roman", serif;">,</span>會先跳過前面<span style="font-family: "Times New Roman", serif;">40bytes</span>的<span style="font-family: "Times New Roman", serif;">DexOptHeader,</span>只取<span style="font-family: "Times New Roman", serif;">DexHeader</span>之後的部份計算<span style="font-family: "Times New Roman", serif;">Checksum,</span>首先<span style="font-family: "Times New Roman", serif;">,</span>會把<span style="font-family: "Times New Roman", serif;">Dex</span>檔案長度先減去<span style="font-family: "Times New Roman", serif;">sizeof(pHeader->magic) + sizeof(pHeader->checksum) (</span>共<span style="font-family: "Times New Roman", serif;">12bytes),</span>從這開始往後用<span style="font-family: "Times New Roman", serif;">alder32</span>計算原本<span style="font-family: "Times New Roman", serif;">Dex</span>檔案大小的值<span style="font-family: "Times New Roman", serif;">,</span>將<span style="font-family: "Times New Roman", serif;">alder32</span>的值與<span style="font-family: "Times New Roman", serif;">pHeader->checksum</span>值比對<span style="font-family: "Times New Roman", serif;">,</span>確認該<span style="font-family: "Times New Roman", serif;">Dex</span>檔案是否有被修改過<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>而經過最佳化過的檔案<span style="font-family: "Times New Roman", serif;">,</span>會加上<span style="font-family: "Times New Roman", serif;">DexOptHeader</span>檔頭<span style="font-family: "Times New Roman", serif;">,</span>與在檔案尾部加上最佳化時所相依的<span style="font-family: "Times New Roman", serif;">Classes</span>資訊<span style="font-family: "Times New Roman", serif;">,</span>因此<span style="font-family: "Times New Roman", serif;">,ODEX</span>的<span style="font-family: "Times New Roman", serif;">Checksum</span>主要是針對<span style="font-family: "Times New Roman", serif;">Dex</span>以外的部份<span style="font-family: "Times New Roman", serif;">,</span>也就是最後面所針對最佳化而加上的訊息進行<span style="font-family: "Times New Roman", serif;">Checksum</span>計算與比對<span style="font-family: "Times New Roman", serif;">,</span>運作的機制為從<span style="font-family: "Times New Roman", serif;">ODEX</span>檔頭往後加上<span style="font-family: "Times New Roman", serif;">pOptHeader->depsOffset</span>的位置<span style="font-family: "Times New Roman", serif;">,</span>與取得檔尾的位置<span style="font-family: "Times New Roman", serif;">,</span>目前的實作為<span style="font-family: "Times New Roman", serif;">end=pOptHeader + pOptHeader->optOffset + pOptHeader->optLength,</span>再透過<span style="font-family: "Times New Roman", serif;">alder32</span>計算從<span style="font-family: "Times New Roman", serif;">depsOffset</span>到<span style="font-family: "Times New Roman", serif;">ODEX</span>檔案結束點的值與<span style="font-family: "Times New Roman", serif;">pOptHeader->checksum</span>值比對<span style="font-family: "Times New Roman", serif;">,</span>確認目前<span style="font-family: "Times New Roman", serif;">ODEX</span>檔案區間是否有被修改過<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>驗證目前的<span style="font-family: "Times New Roman", serif;">ODEX</span>檔案<span style="font-family: "Times New Roman", serif;">,</span>基本上<span style="font-family: "Times New Roman", serif;">,ODEX</span>所加入的節區<span style="font-family: "Times New Roman", serif;">,</span>是在原本的<span style="font-family: "Times New Roman", serif;">DEX</span>檔案前加上<span style="font-family: "Times New Roman", serif;">40bytes</span>的檔頭<span style="font-family: "Times New Roman", serif;">,</span>與在<span style="font-family: "Times New Roman", serif;">DEX</span>檔案最後加上最佳化相關資訊<span style="font-family: "Times New Roman", serif;">,</span>而成為一個<span style="font-family: "Times New Roman", serif;">ODEX</span>檔案<span style="font-family: "Times New Roman", serif;">.</span>概念如下所示<span style="font-family: "Times New Roman", serif;">,</span>未來是否會有變動<span style="font-family: "Times New Roman", serif;">,</span>還請以<span style="font-family: "Times New Roman", serif;">Android</span>最新的<span style="font-family: "Times New Roman", serif;">Source Code</span>為依據<span style="font-family: "Times New Roman", serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 564px;"><colgroup><col width="102"></col><col width="103"></col><col width="104"></col><col width="213"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td bgcolor="#579d1c" rowspan="11" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="102"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ODEX</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
</td><td bgcolor="#579d1c" colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="327"><span style="font-family: "Times New Roman", serif;">ODEX Header<span style="color: yellow;"><span style="font-size: xx-small;"><strong><br />(DexOptHeader)</strong></span></span></span></td></tr>
<tr valign="TOP"><td bgcolor="#00b8ff" rowspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"><span style="font-family: "Times New Roman", serif;">DEX</span></td><td bgcolor="#00b8ff" colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="327"><span style="font-family: "Times New Roman", serif;">DEX Header<span style="color: yellow;"><span style="font-size: xx-small;"><strong><br />(DexHeader)</strong></span></span></span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#00b8ff" rowspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="104"><span style="font-family: "Times New Roman", serif;">DEX Body</span></td><td bgcolor="#00b8ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pStringIds</span></td></tr>
<tr valign="TOP"><td bgcolor="#00b8ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pTypeIds</span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#00b8ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pProtoIds</span></td></tr>
<tr valign="TOP"><td bgcolor="#00b8ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pFieldIds</span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#00b8ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pMethodIds</span></td></tr>
<tr valign="TOP"><td bgcolor="#00b8ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pClassDefs</span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#00b8ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pLinkData</span></td></tr>
<tr valign="TOP"><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="103"></td><td bgcolor="#579d1c" rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="104"><span style="font-family: "Times New Roman", serif;">ODEX Body<span style="color: yellow;"><span style="font-size: xx-small;"><strong><br />(DexOptHeader.depsOffset)</strong></span></span></span></td><td bgcolor="#579d1c" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pClassLookup</span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#579d1c" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="213"><span style="font-family: "Times New Roman", serif;">pRegisterMapPool</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示為<span style="font-family: "Times New Roman", serif;">Dex</span>檔案對應欄位的說明<span style="font-family: "Times New Roman", serif;">,</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 809px;"><colgroup><col width="142"></col><col width="126"></col><col width="509"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">名稱</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">說明</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">ODex Header</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Optimized Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex Header</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">header_item</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">(</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">請看下一個表格有更清楚的檔頭欄位說明</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">)</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">string_ids</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">string_id_item[]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案中所用到的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">UTF-16 LE</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">字串識別</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">ID</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">(</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">String Ids)</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">列表</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">包括內部的命名</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">(e.g., type descriptors) </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">或由程式碼所參考的字串常數物件</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">type_ids</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">type_id_item[]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案中所用的形態名稱識別</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">ID(Type Ids)</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">列表</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">包括檔案中所有參考到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">classes, arrays, or primitive types,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">不管是否有在這檔案中定義</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">只要有參考到的就會納入到此</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">型態名稱也會對應到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">String ID Index.</span></span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">proto_ids</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">proto_id_item[]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Class Method</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">對應的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Prototype IDs,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">在這會包括所有這個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案中參考的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Prototype IDs.</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">field_ids</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">field_id_item[]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Class Field (</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">變數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Type)</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">所對應的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">IDs,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">在這會包括所有這個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案中參考的 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Field IDs.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">method_ids</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">method_id_item[]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Class Method</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">所對應的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">IDs,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">在這會包括所有這個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案中參考的 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Method IDs. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">在檔案中的排序方式會以</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Type Id</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">為主</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">之後參考</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">String ID,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">之後參考</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Proto ID.</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">class_defs</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">class_def_item[]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Class Definitions List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">可用來查詢每個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Class Field/Method,Class Index,Access Flag</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">相關訊息</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果今天要去</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dump</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">所有</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Class/Method/Field</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的訊息時</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,Class Definitions List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">會是基本必要元素之一</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="142"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">link_data</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="126"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">ubyte[]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="509"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Staticlly Linked</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的資料</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">. (mmm,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">不過筆者手中沒有看到有支援這</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Section</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的檔案</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.)</span></span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示為<span style="font-family: "Times New Roman", serif;">DEX</span>檔頭對應欄位的說明<span style="font-family: "Times New Roman", serif;">,</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="136"></col><col width="182"></col><col width="455"></col></colgroup><tbody>
<tr valign="TOP"><th style="background: rgb(136, 136, 136); border: 1px solid rgb(255, 255, 255); color: white; font-size: 11.52px; padding: 4px 8px; text-align: left;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Name</span></span></th><th style="background: rgb(136, 136, 136); border: 1px solid rgb(255, 255, 255); color: white; font-size: 11.52px; padding: 4px 8px; text-align: left;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Format</span></span></th><th style="background: rgb(136, 136, 136); border: 1px solid rgb(255, 255, 255); color: white; font-size: 11.52px; padding: 4px 8px; text-align: left;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Description</span></span></th></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">magic</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">ubyte[8] = DEX_FILE_MAGIC</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">屬於</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">8bytes Magic Code “dex\n035\0″</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">checksum</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">使用</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">zlib </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">adler32</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">所計算的 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">32-bits</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;"> </span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">CheckSum</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">計算的範圍為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案的長度(</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Header->fileSize)</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">減去</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">8 bytes Magic Code</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">與</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">4 bytes CheckSum</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的範圍</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來確保</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案內容沒有損毀</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">signature</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">ubyte[20]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">SHA-1 signature (hash) </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來識別原本的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">(</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">被最佳化以前的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX). SHA-1</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">計算的範圍為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案的長度(</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Header->fileSize)</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">減去</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">8 bytes Magic Code,4 bytes CheckSum</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">與 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">20bytes SHA-1</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的範圍</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來識別最原本的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案的唯一性</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">. (</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">所以被最佳化過後</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">這個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">SHA-1</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">儘能用來識別原本的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">而無法透過</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">ODEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案計算回最原本的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">SHA-1</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">值了</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">).</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">file_size</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">包含</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX Header</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">與到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案的檔案長度 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">(i</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">n bytes).</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">header_size</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint = 0x70</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來記錄目前</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX Header</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的大小 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">(</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">現有版本為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0x70 bytes),</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">可用來做為後續</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Header</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果有改版時</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">最基本的檔頭欄位向前</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">向後相容的依據</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">endian_tag</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint = ENDIAN_CONSTANT</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">預設值為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Little-Endian,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">在這欄位會顯示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">32bits</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">值 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">“0x12345678″. (</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">ㄟ</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">….</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">應該在 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Big-Endian</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">處理器上</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">會轉為 “</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0x78563412”,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">才能表彰出這個值的意義</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">)</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">link_size</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Link Section</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的大小</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">表示該</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案不是靜態連結</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">link_off</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Link Section</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Link Size</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">此值也會為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0.</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式可以參考 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">struct </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DexLink.</span></span></code></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">map_off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Map Item</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">表示這</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DEX</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔案沒有</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Map Item. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式可以參考 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">struct </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">map_list.</span></span></code></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">string_ids_size</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">String IDs List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的總數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">string_ids_off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">String Ids List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">String IDs Size</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">此值也會為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0.</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式可以參考 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">struct </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DexStringId.</span></span></code></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">type_ids_size</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Type IDs List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的總數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">type_ids_off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Type IDs </span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset.</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">type_ids_size</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">這個值亦為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式可以參考 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">struct </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DexTypeId.</span></span></code></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">proto_ids_size</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Prototype IDs List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的總數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">proto_ids_off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Prototype</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;"> IDs </span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset.</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">proto_ids_size</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">這個值亦為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式可以參考 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">struct </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DexProtoId.</span></span></code></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">field_ids_size</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Field IDs List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的總數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">field_ids_off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Field</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;"> IDs </span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset.</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">field_ids_size</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">這個值亦為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式可以參考 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">struct </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DexFieldId.</span></span></code></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">method_ids_size</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Method IDs List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的總數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">method_ids_off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Method</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;"> IDs </span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset.</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">method_ids_size</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">這個值亦為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式可以參考 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">struct </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DexMethodId.</span></span></code></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">class_defs_size</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Class Definitions List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的總數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">class_defs_off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Class Definition</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;"> </span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">List</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset.</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">如果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">class_defs_size</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">這個值亦為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">資料格式可以參考 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">struct </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">DexClassDef.</span></span></code></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">data_size</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Data Section</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的大小</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">. </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">並需為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">sizeof(uint) </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">的偶數倍</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">. (</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">所以就是 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">0,8,16…etc)</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">data_off</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="182"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">uint</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="455"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">用來表示</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Data Section</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">距離</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Dex</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">檔頭的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: xx-small;">Offset.</span></span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>從</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Class </strong></span></span><span style="font-size: small;"><strong>查找</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Method,Field</strong></span></span><span style="font-size: small;"><strong>與相關的</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Types,Prototype</strong></span></span><span style="font-size: small;"><strong>與</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>String.</strong></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>接下來<span style="font-family: "Times New Roman", serif;">,</span>我們以實際的例子<span style="font-family: "Times New Roman", serif;">,</span>從<span style="font-family: "Times New Roman", serif;">Class</span>來查找相關的資訊<span style="font-family: "Times New Roman", serif;">,</span>讓各位可以對<span style="font-family: "Times New Roman", serif;">DEX</span>中所包含的資料與結構更有感覺<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">首先</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們知道</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DEX</span></span><span style="font-size: x-small;">檔案可以是一個包含多個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Classes</span></span><span style="font-size: x-small;">檔案的集合</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">也因此在進行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">分析前</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">要先從</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DEX</span></span><span style="font-size: x-small;">檔頭</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">classDefsSize</span></span><span style="font-size: x-small;">欄位取得目前</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DEX</span></span><span style="font-size: x-small;">檔案所包含的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Classes</span></span><span style="font-size: x-small;">總數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在知道總數後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們便可以選擇所要解析的是第幾個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class,</span></span><span style="font-size: x-small;">接下來筆者假設要</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dump</span></span><span style="font-size: x-small;">出第五個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">的資料</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就以如下的 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct </span></span><span style="font-size: x-small;">並以距離</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔頭</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">pHeader->classDefsOff</span></span><span style="font-size: x-small;">的距離</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">取出第五個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexClassDef</span></span><span style="font-size: x-small;">的資料</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexClassDef {<br />u4 classIdx; /* index into typeIds for this class */<br />u4 accessFlags;<br />u4 superclassIdx; /* index into typeIds for superclass */<br />u4 interfacesOff; /* file offset to DexTypeList */<br />u4 sourceFileIdx; /* index into stringIds for source file name */<br />u4 annotationsOff; /* file offset to annotations_directory_item */<br />u4 classDataOff; /* file offset to class_data_item */<br />u4 staticValuesOff; /* file offset to DexEncodedArray */<br />} DexClassDef;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">再來參考 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexClassDef</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">classDataOff</span></span><span style="font-size: x-small;">欄位</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">得到對應</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Data</span></span><span style="font-size: x-small;">距離</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DEX</span></span><span style="font-size: x-small;">檔頭的位置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">並以如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct</span></span><span style="font-size: x-small;">讀出</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexClassDataHeader </span></span><span style="font-size: x-small;">的資料</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexClassDataHeader {<br />u4 staticFieldsSize;<br />u4 instanceFieldsSize;<br />u4 directMethodsSize;<br />u4 virtualMethodsSize;<br />} DexClassDataHeader;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">並以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Unsigned LEB128</span></span><span style="font-size: x-small;">的方式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">讀出值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">驗證該值格式正確的方式為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果讀出後的指標跟原本距離</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">5 bytes (LEB128</span></span><span style="font-size: x-small;">可編碼為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1-5bytes),</span></span><span style="font-size: x-small;">就確認該</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Usigned LEB128</span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">5</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">bytes</span></span><span style="font-size: x-small;">是否有使用超過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4bits (ptr[4] > 0x0f,</span></span><span style="font-size: x-small;">根據</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Unsigned LEB128</span></span><span style="font-size: x-small;">編碼</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">5</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">bytes</span></span><span style="font-size: x-small;">只會用到前</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4bits). </span></span><span style="font-size: x-small;">如果超過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就返回驗證失敗</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">若驗證無誤</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Unsigned LED128</span></span><span style="font-size: x-small;">編碼方式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">把前四個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Unsigned LEB128</span></span><span style="font-size: x-small;">值讀出來</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">對應到 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexClassDataHeader</span></span><span style="font-size: x-small;">中的 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">staticFieldsSize, instanceFieldsSize, directMethodsSize</span></span><span style="font-size: x-small;">與 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">virtualMethodsSize,</span></span><span style="font-size: x-small;">並以上述</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">static/instance Field</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">direct/virtual Method</span></span><span style="font-size: x-small;">的個數和所對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexField</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexMethod</span></span><span style="font-size: x-small;">用下列的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexClassData</span></span><span style="font-size: x-small;">配置記憶體記錄</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Data</span></span><span style="font-size: x-small;">檔頭與其對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Field/Method</span></span><span style="font-size: x-small;">資料</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexClassData {<br />DexClassDataHeader header;<br />DexField* staticFields;<br />DexField* instanceFields;<br />DexMethod* directMethods;<br />DexMethod* virtualMethods;<br />} DexClassData;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">之後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">依序以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Unsigned LEB128</span></span><span style="font-size: x-small;">編碼讀出 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">staticFields</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">instanceFields </span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">fieldIdx/accessFlags , directMethods/ virtualMethods</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">methodIdx/accessFlags/codeOff. </span></span><span style="font-size: x-small;">筆者把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ClassData</span></span><span style="font-size: x-small;">資料排列的方式透過表格對應如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">由於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Unsigned LEB128</span></span><span style="font-size: x-small;">所編碼的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits</span></span><span style="font-size: x-small;">整數值長度會介於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1-5bytes</span></span><span style="font-size: x-small;">間</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">實際要以幾個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Bytes</span></span><span style="font-size: x-small;">來表示個別的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Unsigned LEB128,</span></span><span style="font-size: x-small;">需根據</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Decode</span></span><span style="font-size: x-small;">的內容為主</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 804px;"><colgroup><col width="158"></col><col width="624"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
長度</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="624"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對應的結構</div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><span style="font-family: "Times New Roman", serif;">4</span>個<span style="font-family: "Times New Roman", serif;">Unsigned LEB128</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="624"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexClassDataHeader {<br />u4 staticFieldsSize;<br />u4 instanceFieldsSize;<br />u4 directMethodsSize;<br />u4 virtualMethodsSize;<br />} DexClassDataHeader;</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><span style="font-family: "Times New Roman", serif;">2</span>個<span style="font-family: "Times New Roman", serif;">Unsigned LEB128 *<span style="font-size: x-small;">staticFieldsSize</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="624"><span style="font-family: "Times New Roman", serif;">typedef struct DexField {<br />u4 fieldIdx; /* index to a field_id_item */<br />u4 accessFlags;<br />} DexField;</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><span style="font-family: "Times New Roman", serif;">2</span>個<span style="font-family: "Times New Roman", serif;">Unsigned LEB128 *<span style="font-size: x-small;"> instanceFieldsSize</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="624"><span style="font-family: "Times New Roman", serif;">typedef struct DexField {<br />u4 fieldIdx; /* index to a field_id_item */<br />u4 accessFlags;<br />} DexField;</span></td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><span style="font-family: "Times New Roman", serif;">3</span>個<span style="font-family: "Times New Roman", serif;">Unsigned LEB128 *<span style="font-size: x-small;">directMethodsSize</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="624"><span style="font-family: "Times New Roman", serif;">typedef struct DexMethod {<br />u4 methodIdx; /* index to a method_id_item */<br />u4 accessFlags;<br />u4 codeOff; /* file offset to a code_item */<br />} DexMethod;</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><span style="font-family: "Times New Roman", serif;">3</span>個<span style="font-family: "Times New Roman", serif;">Unsigned LEB128 *<span style="font-size: x-small;"> virtualMethodsSize</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="624"><span style="font-family: "Times New Roman", serif;">typedef struct DexMethod {<br />u4 methodIdx; /* index to a method_id_item */<br />u4 accessFlags;<br />u4 codeOff; /* file offset to a code_item */<br />} DexMethod;</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">取得上述 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexClassDef</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Data</span></span><span style="font-size: x-small;">後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們會得到相關的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class/Field/Method Index,</span></span><span style="font-size: x-small;">接下來就透過這些</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Index</span></span><span style="font-size: x-small;">取得對應的字串</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">首先把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Index</span></span><span style="font-size: x-small;">透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex Header</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typeIdsOff</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexTypeId</span></span><span style="font-size: x-small;">取得對應</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Index</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexTypeId</span></span><span style="font-size: x-small;">的值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexTypeId {<br />u4 descriptorIdx; /* index into stringIds list for type descriptor */<br />} DexTypeId;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">再把取得的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">descriptorIdx</span></span><span style="font-size: xx-small;">透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Dex Header</span></span><span style="font-size: xx-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">stringIdsOff</span></span><span style="font-size: xx-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">struct </span><span style="font-size: x-small;">DexStringId</span></span><span style="font-size: x-small;">取得對應</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">descriptorIdx </span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexStringId </span></span><span style="font-size: x-small;">的值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexStringId {<br />u4 stringDataOff; /* file offset to string_data_item */<br />} DexStringId;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">距離</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔頭 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">stringDataOff</span></span><span style="font-size: x-small;">就是對應字串所在位置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span><span style="font-size: x-small;">DexClassDef </span><span style="font-size: x-small;">(</span><span style="font-size: x-small;">classIdx</span><span style="font-size: x-small;">/</span><span style="font-size: x-small;">superclassIdx</span><span style="font-size: x-small;">)</span><span style="font-size: x-small;">->Type Id Index (DexTypeId)->Desceiptor Id Index(DexStringId)->StringDataOffset</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">有關</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class/Method/Field</span></span><span style="font-size: x-small;">對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">accessFlags Bit</span></span><span style="font-size: x-small;">意義如下表</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 754px;"><colgroup><col width="136"></col><col width="145"></col><col width="228"></col><col width="203"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Access Flag Bit</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Class</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Method</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Field</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000001</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PUBLIC</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PUBLIC</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PUBLIC</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000002</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PRIVATE</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PRIVATE</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PRIVATE</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000004</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PROTECTED</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PROTECTED</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PROTECTED</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000008</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STATIC</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STATIC</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STATIC</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000010</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">FINAL</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">FINAL</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">FINAL</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000020</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SYNCHRONIZED</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000040</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">BRIDGE</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">VOLATILE</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000080</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">VARARGS</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">TRANSIENT</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000100</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">NATIVE</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000200</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">INTERFACE</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000400</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ABSTRACT</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ABSTRACT</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x000800</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STRICT</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x001000</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SYNTHETIC</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SYNTHETIC</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SYNTHETIC</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x002000</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ANNOTATION</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x004000</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ENUM</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ENUM</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x008000</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">MIRANDA</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x010000</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">VERIFIED</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">CONSTRUCTOR</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0x020000</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">OPTIMIZED</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="228"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">DECLARED_SYNCHRONIZED</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="203"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">?</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">如果</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Definition</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">interfacesOff</span></span><span style="font-size: xx-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0,</span></span><span style="font-size: xx-small;">則以 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexTypeList</span></span><span style="font-size: x-small;">在距離</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔頭</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">interfacesOff</span></span><span style="font-size: xx-small;">的位置讀取出</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Interface</span></span><span style="font-size: xx-small;">的資訊</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexTypeList {<br />u4 size; /* #of entries in list */<br />DexTypeItem list[1]; /* entries */<br />} DexTypeList;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Interfaces </span></span><span style="font-size: x-small;">總數為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">size,</span></span><span style="font-size: x-small;">在之後依據</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">size</span></span><span style="font-size: x-small;">個數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">銜接對應的 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexTypeItem</span></span><span style="font-size: x-small;">內容</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexTypeItem {<br />u2 typeIdx; /* index into typeIds */<br />} DexTypeItem;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">如同取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Description</span></span><span style="font-size: x-small;">字串一樣</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexTypeItem</span></span><span style="font-size: x-small;">會取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Type IDs Index,</span></span><span style="font-size: x-small;">之後依循如下的流程</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Interface Name (</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">framework.jar</span></span><span style="font-size: x-small;">為例</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Class “android/os/Binder” </span></span><span style="font-size: x-small;">有如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Interface “android/os/IBinder”,</span></span><span style="font-size: x-small;">或</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class “android/accessibilityservice/IEventListener” </span></span><span style="font-size: x-small;">有如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Interface “android/os/IInterface”)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span><span style="font-size: x-small;">Interface Index(DexTypeItem)->Type Id Index (DexTypeId)->Desceiptor Id Index(DexStringId)->StringDataOffset</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">為例</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會以每個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method struct DexMethod </span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">methodIdx</span><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔頭的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">methodIdsOff,</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexMethodId,</span></span><span style="font-size: x-small;">取出該</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Index/Prototype Index/Name Index (</span></span><span style="font-size: x-small;">可以看到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">…</span></span><span style="font-size: x-small;">都是透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Index,</span></span><span style="font-size: x-small;">只要其中有越多同名的字串</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就可以節省越多的儲存空間成本</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">).</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexMethodId {<br />u2 classIdx; /* index into typeIds list for defining class */<br />u2 protoIdx; /* index into protoIds for method prototype */<br />u4 nameIdx; /* index into stringIds for method name */<br />} DexMethodId;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Name Index (nameIdx)</span></span><span style="font-size: x-small;">取得字串示意如下</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method Index(DexMethod)->Method Ids Offset (DexMethodId)->Name Index->Desceiptor Id Index(DexStringId)->StringDataOffset</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">而</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Prototype Index (protoIdx)</span></span><span style="font-size: x-small;">會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔頭的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">protoIdsOff,</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexProtoId</span></span><span style="font-size: x-small;">取出有關</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Prototype</span></span><span style="font-size: x-small;">的相關資訊</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexProtoId {<br />u4 shortyIdx; /* index into stringIds for shorty descriptor */<br />u4 returnTypeIdx; /* index into typeIds list for return type */<br />u4 parametersOff; /* file offset to type_list for parameter types */<br />} DexProtoId;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">其中如果 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">parametersOff</span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0,</span></span><span style="font-size: x-small;">則會以距離</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔頭</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">parametersOff</span></span><span style="font-size: x-small;">距離</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexTypeList</span></span><span style="font-size: x-small;">並根據</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">size </span></span><span style="font-size: x-small;">取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">TypeList</span></span><span style="font-size: x-small;">總量</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">而 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexTypeItem</span></span><span style="font-size: x-small;">中的 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typeIdx</span></span><span style="font-size: x-small;">就會在對應到每個函式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">參數所對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Type Index,</span></span><span style="font-size: x-small;">並可由此取得最後的參數名稱</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexTypeList {<br />u4 size; /* #of entries in list */<br />DexTypeItem list[1]; /* entries */<br />} DexTypeList;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">同時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">函式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">的返回值型態會透過 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">returnTypeIdx</span></span><span style="font-size: x-small;">來反查</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">舉</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">framework.jar</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class android/os/IBinder</span></span><span style="font-size: x-small;">一個有</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4</span></span><span style="font-size: x-small;">個參數的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method “transact”</span></span><span style="font-size: x-small;">例子為例</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Method</span></span><span style="font-size: x-small;">參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(ILandroid/os/Parcel;Landroid/os/Parcel;I)</span></span><span style="font-size: x-small;">會由左而右</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">透過 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexTypeList</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">list</span></span><span style="font-size: x-small;">依序往後擺放</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 527px;"><colgroup><col width="158"></col><col width="347"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">參數左</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><br /></span></span><span style="color: red;"><span style="font-size: xx-small;">I</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="347"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexTypeItem list[0]</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Landroid/os/Parcel;</span></span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="347"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexTypeItem list[1]</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Landroid/os/Parcel;</span></span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="347"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexTypeItem list[2]</span></span></div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="158"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">參數右</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><br /></span></span><span style="color: red;"><span style="font-size: xx-small;">I</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="347"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexTypeItem list[3]</span></span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">並透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">returnTypeIdx</span></span><span style="font-size: x-small;">取得該函式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">返回值的形態字串 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Z. </span></span><span style="font-size: x-small;">我們可以看到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">這些型態的表述方式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">跟透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">JNI</span></span><span style="font-size: x-small;">介面</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">要由</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">C</span></span><span style="font-size: x-small;">程式調用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">函式時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">所描述的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">函式的形態是一致的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">請自行參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">JNI</span></span><span style="font-size: x-small;">中對於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Type Signature</span></span><span style="font-size: x-small;">的說明</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">例如</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">:</span></span><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-size: x-small;">http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html</span></a></span></span><span style="font-size: x-small;"> ).</span><span style="font-size: x-small;">而 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">shortyIdx</span></span><span style="font-size: x-small;">則直接對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">String Index.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">有關</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">所對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">位置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">則可透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexMethod</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">codeOff</span></span><span style="font-size: x-small;">取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexCode,</span></span><span style="font-size: x-small;">這</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct</span></span><span style="font-size: x-small;">中會包含</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">函式中所用到的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Registers</span></span><span style="font-size: x-small;">總數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(registersSize),Method</span></span><span style="font-size: x-small;">所包含的參數個數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(insSize),Method</span></span><span style="font-size: x-small;">實作中用來做為呼叫其他</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">帶入參數的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Registers</span></span><span style="font-size: x-small;">個數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(outsSize),Method</span></span><span style="font-size: x-small;">實作中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Try/Catch</span></span><span style="font-size: x-small;">的個數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(triesSize),</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">為單位的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">實作指令集個數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(insnsSize)</span></span><span style="font-size: x-small;">與最後真正</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">的實作內容</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(insns).</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexCode {<br />u2 registersSize;<br />u2 insSize;<br />u2 outsSize;<br />u2 triesSize;<br />u4 debugInfoOff; /* file offset to debug info stream */<br />u4 insnsSize; /* size of the insns array, in u2 units */<br />u2 insns[1];<br />/* followed by optional u2 padding */<br />/* followed by try_item[triesSize] */<br />/* followed by uleb128 handlersSize */<br />/* followed by catch_handler_item[handlersSize] */<br />} DexCode;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Try/Catch</span></span><span style="font-size: x-small;">的資訊會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexTry</span></span><span style="font-size: x-small;">取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">所在位置為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DexCode-> insns ByteCode</span></span><span style="font-size: x-small;">實作的結尾(結尾位置為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4bytes</span></span><span style="font-size: x-small;">的倍數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">).</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexTry {<br />u4 startAddr; /* start address, in 16-bit code units */<br />u2 insnCount; /* instruction count, in 16-bit code units */<br />u2 handlerOff; /* offset in encoded handler data to handlers */<br />} DexTry;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">而有關</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Field</span></span><span style="font-size: x-small;">的部份</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會以每個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Field struct DexField </span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">fieldIdx ,</span></span><span style="font-size: x-small;">透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔頭的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">fieldIdsOff,</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct </span></span><span style="font-size: x-small;">DexFieldId</span><span style="font-size: x-small;">,</span><span style="font-size: x-small;">取出該</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Field</span></span><span style="font-size: x-small;">對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Index/Prototype Index/Name Index</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typedef struct DexFieldId {<br />u2 classIdx; /* index into typeIds list for defining class */<br />u2 typeIdx; /* index into typeIds for field type */<br />u4 nameIdx; /* index into stringIds for field name */<br />} DexFieldId;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">如同前述對</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">資訊的解析</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,classIdx</span></span><span style="font-size: x-small;">可以作為所屬</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class </span></span><span style="font-size: x-small;">的 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Type Index,</span></span><span style="font-size: x-small;">而</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">typeIdx</span></span><span style="font-size: x-small;">可以作為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Field</span></span><span style="font-size: x-small;">本身型態的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Type Index,</span></span><span style="font-size: x-small;">最後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">nameIdx</span></span><span style="font-size: x-small;">則做為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Field</span></span><span style="font-size: x-small;">名稱的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sreing ID Index.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>DEX SHA-1 S</strong></span><span style="font-size: small;"><strong>ignature</strong></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">DEX</span>檔頭會帶一個<span style="font-family: "Times New Roman", serif;">160-bits </span>的<span style="font-family: "Times New Roman", serif;">SHA-1</span>簽名<span style="font-family: "Times New Roman", serif;">,</span>主要功能是用來識別最佳化前的<span style="font-family: "Times New Roman", serif;">DEX</span>檔案<span style="font-family: "Times New Roman", serif;">,</span>作為最佳化前<span style="font-family: "Times New Roman", serif;">DEX</span>檔案唯一的識別碼<span style="font-family: "Times New Roman", serif;">,</span>一旦<span style="font-family: "Times New Roman", serif;">DEX</span>檔案有經過最佳化或<span style="font-family: "Times New Roman", serif;">Byte-Swapped(</span>如果把<span style="font-family: "Times New Roman", serif;">Little-Endian</span>的<span style="font-family: "Times New Roman", serif;">Dex</span>放到<span style="font-family: "Times New Roman", serif;">Big-Endian</span>環境執行<span style="font-family: "Times New Roman", serif;">),</span>該<span style="font-family: "Times New Roman", serif;">SHA-1</span>值就會無法被計算回來<span style="font-family: "Times New Roman", serif;">,</span>該值的意義主要只用於識別而非驗證檔案是否有被修改<span style="font-family: "Times New Roman", serif;">.</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">計算</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">SHA-1</span></span><span style="font-size: x-small;">簽名的方式為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔案長度先減去</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">sizeof(pHeader->magic) + sizeof(pHeader->checksum) + kSHA1DigestLen (8 bytes Magic Code,4bytes Checksum</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">20 bytes SHA-1 Digest),</span></span><span style="font-size: x-small;">然後再透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">SHA-1</span></span><span style="font-size: x-small;">計算</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔案數值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">只要該檔案有經過最佳化</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">計算的結果就會與原本的簽名不同</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Dalvik</strong></span></span><span style="font-size: small;"><strong>虛擬器的</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>ByteCode</strong></span></span><span style="font-size: small;"><strong>指令格式</strong></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Android</span></span><span style="font-size: x-small;">文件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">筆者在這表述方式為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">每個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">[]</span></span><span style="font-size: x-small;">都代表一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">由低位元到高位元</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,op</span></span><span style="font-size: x-small;">等於一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">8bits</span></span><span style="font-size: x-small;">的指令碼</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,A/B/C/D/E/F/G/H </span></span><span style="font-size: x-small;">代表一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4bits</span></span><span style="font-size: x-small;">的數值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">可用來代表暫存器 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0-15</span></span><span style="font-size: x-small;">或是數值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">或是兩個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">AA/BB/CC/DD/EE/FF/GG/HH</span></span><span style="font-size: x-small;">代表一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">8bits</span></span><span style="font-size: x-small;">的數值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">表彰暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0-255</span></span><span style="font-size: x-small;">或是數值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.. </span></span><span style="font-size: x-small;">或是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">AAAA/BBBB/CCCC/DDDD/EEEE/FFFF/GGGG/HHHH</span></span><span style="font-size: x-small;">代表一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">的數值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 806px;"><colgroup><col width="124"></col><col width="242"></col><col width="408"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
指令集格式</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
語法</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
範例</div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[op|</span><span style="font-family: monospace;"><span style="font-size: xx-small;">ØØ</span></span><span style="font-size: xx-small;">]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Op</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[0000]</span></span></div>
<div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">nop</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[op|B|A]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Op vA, vB</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[0110]<br />move v0, v1</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[0760]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">move-object v0, v6</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Op vA, #+B</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[1214]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const/4 v4, #int 1 // #1</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[op|AA]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Op vAA</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[0a02]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">move-result v2</span></span></div>
</td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Op +AA</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[28ec]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">goto 0030 // -0014</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[op|</span><span style="font-family: monospace;"><span style="font-size: xx-small;">ØØ</span></span><span style="font-size: xx-small;">] [AAAA]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Op +AAAA</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[2900 56ff]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">goto/16 0005 // -00aa</span></span></div>
</td></tr>
<tr class="" valign="TOP"><td rowspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[op|AA] [BBBB]</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op vAA, vBBBB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[0801 1a00]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">move-object/from16 v1, v26</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op vAA, +BBBB</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[3805 f5ff]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">if-eqz v5, 002e // -000b</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op vAA, #+BBBB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[1306 0a00]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const/16 v6, #int 10 // #a</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op vAA, #+BBBB0000</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op vAA, #+BBBB000000000000</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[1504 0100] (</span><span style="font-family: monospace;"><span style="font-size: xx-small;">const/high16 vAA, #+BBBB0000)</span></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const/high16 v4, #int 65536 // #1</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[1900 f07f] (</span><span style="font-family: monospace;"><span style="font-size: xx-small;">const-wide/high16 vAA, #+BBBB000000000000)</span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const-wide/high16 v0, #long 9218868437227405312 // #7ff0</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op vAA, type@BBBB</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op vAA, field@BBBB</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op vAA, string@BBBB</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[1c00 090e](</span><span style="font-family: monospace;"><span style="font-size: xx-small;">const-class vAA, type@BBBB</span></span><span style="font-size: xx-small;"> )</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const-class v0, [F // class@0e09</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">(</span><span style="font-family: monospace;"><span style="font-size: xx-small;">s</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>staticop </em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">vAA, field@BBBB</span></span><span style="font-size: xx-small;"> )</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[1a02 dd0d](</span><span style="font-family: monospace;"><span style="font-size: xx-small;">const-string vAA, string@BBBB</span></span><span style="font-size: xx-small;"> )</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const-string v2, “Class doesn’t implement Cloneable” // string@0ddd</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[op|AA] [BB|CC]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vAA, vBB, vCC</span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[2d00 0405](</span><span style="font-family: monospace;"><span style="font-size: xx-small;">cmp</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>kind </em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">vAA, vBB, vCC</span></span><span style="font-size: xx-small;">)</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">cmpl-float v0, v4, v5</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vAA, vBB, #+CC</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[d804 0401](</span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>binop</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">/lit8 vAA, vBB, #+CC</span></span><span style="font-size: xx-small;"> )</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">add-int/lit8 v4, v4, #int 1 // #01</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[op|B|A] [CCCC]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vA, vB, +CCCC</span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[3376 1400] (</span><span style="font-family: monospace;"><span style="font-size: xx-small;">if-</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>test </em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">vA, vB, +CCCC</span></span><span style="font-size: xx-small;"> )</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">if-ne v6, v7, 001a // +0014</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vA, vB, #+CCCC</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[d209 e803] 7(</span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>binop</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">/lit16 vA, vB, #+CCCC</span></span><span style="font-size: xx-small;"> )</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">mul-int/lit16 v9, v0, #int 1000 // #03e8</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vA, vB, type@CCCC</span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vA, vB, field@CCCC</span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[2394 0a0e] (</span><span style="font-family: monospace;"><span style="font-size: xx-small;">new-array vA, vB, type@CCCC</span></span><span style="font-size: xx-small;"> )</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">new-array v4, v9, [I // class@0e0a</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[2049 c600] (</span><span style="font-family: monospace;"><span style="font-size: xx-small;">instance-of vA, vB, type@CCCC</span></span><span style="font-size: xx-small;">)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">instance-of v9, v4, Ljava/io/Serializable; // class@00c6</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vA, vB, fieldoff@CCCC</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-family: monospace;"><span style="font-size: xx-small;">[op|ØØ]</span></span><span style="font-family: monospace;"><span style="font-size: xx-small;"><em>[</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">AAAA</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>lo] [</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">AAAA</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>hi</em></span></span><span style="font-size: xx-small;"> ]</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">+AAAAAAAA</span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">(</span><span style="font-family: monospace;"><span style="font-size: xx-small;">goto/32 +AAAAAAAA)</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-family: monospace;"><span style="font-size: xx-small;">[op|ØØ] [AAAA] [BBBB]</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vAAAA, vBBBB</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">(</span><span style="font-family: monospace;"><span style="font-size: xx-small;">move-object/16 vAAAA, vBBBB</span></span><span style="font-size: xx-small;"> )</span></span></td></tr>
<tr class="alt" valign="TOP"><td rowspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-family: monospace;"><span style="font-size: xx-small;">[op|AA] [BBBB</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>lo] [</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">BBBB</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>hi]</em></span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vAA, #+BBBBBBBB</span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">(</span><span style="font-family: monospace;"><span style="font-size: xx-small;">const vAA, #+BBBBBBBB)</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vAA, +BBBBBBBB</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">(</span><span style="font-family: monospace;"><span style="font-size: xx-small;">packed-switch vAA, +BBBBBBBB</span></span><span style="font-size: xx-small;"> )</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vAA, string@BBBBBBBB</span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">(</span><span style="font-family: monospace;"><span style="font-size: xx-small;">const-string/jumbo vAA, string@BBBBBBBB</span></span><span style="font-size: xx-small;">)</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-family: monospace;"><span style="font-size: xx-small;">[op|B|A] [CCCC] [E|D|G|F]</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=5</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE, vF, vG, vA}, meth@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=5</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE, vF, vG, vA}, type@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=4</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE, vF, vG}, </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>kind</em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=3</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE, vF}, </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>kind</em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=2</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE}, </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>kind</em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=1</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD}, </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>kind</em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=0</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{}, </span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>kind</em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">@CCCC</span></span><span style="font-size: xx-small;"></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">and</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=5</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE, vF, vG, vA}, vtaboff@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=4</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE, vF, vG}, vtaboff@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=3</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE, vF}, vtaboff@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=2</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE}, vtaboff@CCCC</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=1</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD}, vtaboff@CCCC</span></span><span style="font-size: xx-small;"></span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[7020 090a 2100] (</span><span style="font-family: monospace;"><span style="font-size: xx-small;">invoke-</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>kind </em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">{vD, vE, vF, vG, vA}, meth@CCCC</span></span>)</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">invoke-direct {v1, v2}, Ljava/lang/AssertionError;.<init>:(Ljava/lang/Object;)V // method@0a09</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[2420 0a0e 6500] (filled-new-array {vD, vE, vF, vG, vA}, type@CCCC)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">filled-new-array {v5, v6}, [I // class@0e0a</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[f840 fb00 1032]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">+invoke-virtual-quick {v0, v1, v2, v3}, [00fb] // vtable #00fb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[f830 fa00 1002]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">+invoke-virtual-quick {v0, v1, v2}, [00fa] // vtable #00fa</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[f820 d300 1000]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">+invoke-virtual-quick {v0, v1}, [00d3] // vtable #00d3</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-family: monospace;"><span style="font-size: xx-small;">[op|B|A]</span></span><span style="font-family: monospace;"><span style="font-size: xx-small;"><em> [CC</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">DD] [F|E|H|G]</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=5</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vE, vF, vG, vH, vA}, vtaboff@CC, iface@DD</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=4</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vE, vF, vG, vH}, vtaboff@CC, iface@DD</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=3</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vE, vF, vG}, vtaboff@CC, iface@DD</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=2</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vE, vF}, vtaboff@CC, iface@DD</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>[</em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>B=1</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>] </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vE}, vtaboff@CC, iface@DD</span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"></td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-family: monospace;"><span style="font-size: xx-small;">[op|AA</span></span><span style="font-family: monospace;"><span style="font-size: xx-small;"><em>] [</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">BBBB] [CCCC]</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vCCCC .. vNNNN}, meth@BBBB</span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vCCCC .. vNNNN}, type@BBBB</span></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>(where </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>NNNN = CCCC+AA-1</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>, that is </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>A</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em> determines the count </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>0..255</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>, and </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>C</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em> determines the first register)</em></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>and</em></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vCCCC .. vNNNN}, vtaboff@BBBB</span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>(where </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>NNNN = CCCC+AA-1</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>, that is </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>A</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em> determines the count </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>0..255</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>, and </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>C</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em> determines the first register)</em></span></span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[7609 6502 0000]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">invoke-direct/range {v0, v1, v2, v3, v4, v5, v6, v7, v8}, Landroid/view/animation/TranslateAnimation;.<init>:(IFIFIFIF)V // method@0265</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[7701 7703 1100]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">invoke-static/range {v17}, Lcom/android/launcher2/AllApps3D$RolloRS;.access$400:(Lcom/android/launcher2/AllApps3D$RolloRS;)F // method@0377 </span><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="mailto:method@2b49" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-size: xx-small;">method@2b49</span></a></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[7803 8a00 1500]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">invoke-interface/range {v21, v22, v23}, Landroid/content/SharedPreferences;.getBoolean:(Ljava/lang/String;Z)Z // method@008a</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[f91b fc00 0400]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">+invoke-virtual-quick/range {v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30}, [00fc] // vtable #00fc</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-family: monospace;"><span style="font-size: xx-small;">[op|AA] [BBCC] [DDDD]</span></span><span style="font-size: xx-small;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">{vDDDD .. vNNNN}, vtaboff@BB, iface@CC</span></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>(where </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>NNNN = DDDD+AA-1</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>, that is </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>A</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em> determines the count </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>0..255</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>, and </em></span></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>D</em></span></span></code><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em> determines the first register)</em></span></span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"></td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="124"><span style="font-family: "Times New Roman", serif;"><span style="font-family: monospace;"><span style="font-size: xx-small;">[op|AA]</span></span><span style="font-family: monospace;"><span style="font-size: xx-small;"><em> [</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">BBBB</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>lo] [</em></span></span><span style="font-family: monospace;"><span style="font-size: xx-small;">BBBB] [BBBB] [BBBB</span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>hi]</em></span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;"><em>op </em></span></span></code><span style="font-family: monospace;"><span style="font-size: xx-small;">vAA, #+BBBBBBBBBBBBBBBB</span></span><span style="font-size: xx-small;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="408"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[1807 ffff 0000 ffff 0000]</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const-wide v7, #double 0.000000 // #0000ffff0000ffff</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">[1803 6d9c 2e3a 42ce 478e]</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">const-wide v3, #double -0.000000 // #8e47ce423a2e9c6d</span></span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">從</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dalvik</span></span><span style="font-size: x-small;">指令集來看</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">比較像是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CISC</span></span><span style="font-size: x-small;">架構的指令集思維</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">每個指令基本單位為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits,</span></span><span style="font-size: x-small;">最長的指令需要</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">80bits(10bytes)</span></span><span style="font-size: x-small;">的長度</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">根據不同指令的需求</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">可以有</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">倍數的延伸</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">這跟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM RISC</span></span><span style="font-size: x-small;">架構下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會以固定</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits</span></span><span style="font-size: x-small;">或</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">完成一個指令的設計取向有所不同</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">反而比較接近</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">x86 CISC</span></span><span style="font-size: x-small;">架構下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">指令可以根據設計有不同長度的延伸</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">例如下列</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">x86</span></span><span style="font-size: x-small;">指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1,2,7</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">11 bytes</span></span><span style="font-size: x-small;">的例子</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(1bytes)0×48 = dec eax</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(2bytes)0×89 F9= mov ecx,edi</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(7bytes)0x8B BC 24 A4 01 00 00 = mov edi,dword ptr [esp+000001A4h]</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(11bytes)0×81 BC 24 14 01 00 00 FF 00 00 00 = cmp dword ptr [esp+00000114h],0FFh</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Dalvik ByteCode</strong></span></span><span style="font-size: small;"><strong>與</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Sun ByteCode</strong></span></span><span style="font-size: small;"><strong>的進一步說明</strong></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik </span></span><span style="font-size: x-small;">虛擬器指令集最多可以支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">256</span></span><span style="font-size: x-small;">個暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">每個暫存器都會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FP</span></span><span style="font-size: x-small;">對應到一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits</span></span><span style="font-size: x-small;">的記憶體位置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">除了在指令執行階段會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">以目前</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">的實作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會用到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">R0,R1,R2,R3,R9</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">R10</span></span><span style="font-size: x-small;">共</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">6</span></span><span style="font-size: x-small;">個暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">)</span></span><span style="font-size: x-small;">對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">指令實作進行加速外</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">主要的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">暫存器都是透過外部的記憶體來暫存</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">模擬為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">虛擬器中的暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">接下來</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們透過相同的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">函式呼叫程式碼</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">分別編譯為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ByteCode</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java ByteCode</span></span><span style="font-size: x-small;">進行比較</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">了解兩者在實現上的差異</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">首先</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">以如下的函式呼叫為例</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">Main1(111);</span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"> (</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">函式原型</span></span><span style="font-family: "Times New Roman", serif;"><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>void</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Main1(</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> A) </span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">dalvik</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">中</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">的實現為</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">[1304 6f00] const/16 v4, #int 111 // #6f</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">[0800 2400] move-object/from16 v0, v36 //</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">暫存器</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">36</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">指到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">TestAA Class Object</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">本身</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">[0141] move v1, v4</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">[f820 f900 1000] +invoke-virtual-quick {v0, v1}, [00f9] // vtable #00f9</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">sun Java</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,ByteCode </span></span><span style="font-size: x-small;">實現為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">會把函式參數由左往右推入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">11: aload_0 // </span></span><span style="font-size: x-small;">把區域變數 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 (</span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">指到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">TestAA Class Object</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">本身</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">) </span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">推到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">Stack</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">中</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">12: bipush 111 //Push 1 byte (111) </span></span><span style="font-size: x-small;">到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack</span></span><span style="font-size: x-small;">中</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">14: invokevirtual #58; //Method Main1:(I)V</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">不過以指令集個數而言</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Dalvik Dx</span></span><span style="font-size: x-small;">顯然做了沒有效率的轉譯</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">先把值放到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v4</span></span><span style="font-size: x-small;">暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">之後再轉給</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v1,</span></span><span style="font-size: x-small;">其實可以直接轉譯為</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span><span style="font-size: x-small;"><span style="text-decoration-line: underline;">const/16 v1, </span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"><span style="text-decoration-line: underline;">#int 111 // #6f</span></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">就可以省去</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">1</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">個 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">move</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">指令 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">(</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">共</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">2bytes)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">再以如下的函式呼叫為例</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> v2=Main2(111,222);</span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"> (</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">函式原型為 </span></span><span style="font-family: "Times New Roman", serif;"><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Main2(</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> A,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> B)</span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">dalvik</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">中</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">的實現為</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">[1304 6f00] const/16 v4, #int 111 // #6f</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">[1305 de00] const/16 v5, #int 222 // #de</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">[0800 2400] move-object/from16 v0, v36 </span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">//</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">暫存器</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">36</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">指到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">TestAA Class Object</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">本身</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">[0141] move v1, v4</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">[0152] move v2, v5</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">[f830 fa00 1002] +invoke-virtual-quick {v0, v1, v2}, [00fa] // vtable #00fa</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">[0a1f] move-result v31 //</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">把</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Return</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">值存到暫存器</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">31</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">sun Java</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">中</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,ByteCode </span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">實現為 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">(</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">會把函式參數由左往右推入</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Stack)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">17: aload_0 // </span></span><span style="font-size: x-small;">把區域變數 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 (</span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">指到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">TestAA Class Object</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">本身</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">) </span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">推到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">Stack</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">中</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">18: bipush 111 //Push 1 byte (111) </span></span><span style="font-size: x-small;">到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack</span></span><span style="font-size: x-small;">中</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">20: sipush 222 //Push 2 byte (Short) (222) </span></span><span style="font-size: x-small;">到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack</span></span><span style="font-size: x-small;">中</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">23: invokevirtual #60; //Method Main2:(II)I</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">26: istore_2 //</span></span><span style="font-size: x-small;">把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">return</span></span><span style="font-size: x-small;">值存到區域變數 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>相比<span style="font-family: "Times New Roman", serif;">Sun</span>的<span style="font-family: "Times New Roman", serif;">Java Code</span>而言<span style="font-family: "Times New Roman", serif;">,</span>還是多了兩次沒有必要的<span style="font-family: "Times New Roman", serif;">Move</span>動作<span style="font-family: "Times New Roman", serif;">,</span>浪費了<span style="font-family: "Times New Roman", serif;">2</span>個指令共<span style="font-family: "Times New Roman", serif;">4</span>個<span style="font-family: "Times New Roman", serif;">bytes</span>的空間<span style="font-family: "Times New Roman", serif;">.</span>可能是筆者對<span style="font-family: "Times New Roman", serif;">Google</span>大師期待過高<span style="font-family: "Times New Roman", serif;">…..@_@,</span>在比較<span style="font-family: "Times New Roman", serif;">Dex ByteCode</span>的一些邏輯後<span style="font-family: "Times New Roman", serif;">,</span>其實還是有待改善的部份<span style="font-family: "Times New Roman", serif;">,</span>但不可否認的<span style="font-family: "Times New Roman", serif;">Dalvik</span>整個實作<span style="font-family: "Times New Roman", serif;">,</span>是一個很不錯的作品<span style="font-family: "Times New Roman", serif;">,</span>值得有志於了解模擬器實作的人<span style="font-family: "Times New Roman", serif;">,</span>花時間深入理解<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">我們可以看到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在函式參數傳遞時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Dalvik</span></span><span style="font-size: x-small;">會選擇以暫存器的方式傳遞</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">以便對應到底層實作時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">可以透過處理器本身的暫存器加速指令集的效率</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">而</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java Vm</span></span><span style="font-size: x-small;">的函數參數的傳遞</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">則是透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack,</span></span><span style="font-size: x-small;">由左往右把函式參數推到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack</span></span><span style="font-size: x-small;">中 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">跟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">C</span></span><span style="font-size: x-small;">的由右往左推</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">是相反的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">).</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">在函式參數的返回值部分</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Dalvik</span></span><span style="font-size: x-small;">會透過暫存器返回</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">再由呼叫端儲存到自己的暫存器中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">這點跟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">C </span></span><span style="font-size: x-small;">語言也是比較類似的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">),</span></span><span style="font-size: x-small;">反之</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Sun Java </span></span><span style="font-size: x-small;">虛擬器的函式返回值會放在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">再由呼叫端從</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack</span></span><span style="font-size: x-small;">取出放到本地的區域變數中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">顧名思義指令集會以一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Byte</span></span><span style="font-size: x-small;">的長度來定義</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">但是在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,ByteCode</span></span><span style="font-size: x-small;">的單位是以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">為單位</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(Dalvik</span></span><span style="font-size: x-small;">目前共有約</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">230</span></span><span style="font-size: x-small;">個指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">),</span></span><span style="font-size: x-small;">通常第一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Byte</span></span><span style="font-size: x-small;">為指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">第二個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Byte</span></span><span style="font-size: x-small;">為使用的暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">一個基本指令集的描述</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會需要</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16-bits (1byte </span></span><span style="font-size: x-small;">指令 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+ 1bytes</span></span><span style="font-size: x-small;">暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">),</span></span><span style="font-size: x-small;">一個最簡單的例子就是</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">return-void = 0e00</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">return v1 = 0f01</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">return v2 = 0f02</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">return-object v1 = 1101</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">另一種組合就是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32-bits</span></span><span style="font-size: x-small;">的指令集組合</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如下所示</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">可以用各</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4 bits</span></span><span style="font-size: x-small;">代表目標與來源暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Offset.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+iput-quick v2, v3, [obj+0120] = f532 2001</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+iput-quick v1, v3, [obj+0118] = f531 1801</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+iput-quick v0, v1, [obj+0110] = f510 1001</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+iput-object-quick v1, v0, [obj+00d8] = f701 d800</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">其次</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">還有</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">48-bits</span></span><span style="font-size: x-small;">的組合</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+invoke-virtual-quick {v6, v5}, [00d1] = f820 d100 5600</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+invoke-virtual-quick {v6, v2}, [00d3] = f820 d300 2600</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+invoke-virtual-quick {v6, v3}, [0034] = f820 3400 3600</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+invoke-virtual-quick {v2}, [01b7] = f810 b701 0200</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Android</span></span><span style="font-size: x-small;">文件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Dalvik ByteCode</span></span><span style="font-size: x-small;">在設計初期</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">希望</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Machine Model </span></span><span style="font-size: x-small;">與 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Calling Conventions</span></span><span style="font-size: x-small;">能儘量接近於真實系統與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">C</span></span><span style="font-size: x-small;">風格的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Calling Conventions. Dalvik</span></span><span style="font-size: x-small;">虛擬器為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register-Based,</span></span><span style="font-size: x-small;">並會根據每個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">所需要的函式參數或是區域變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在該</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">被執行時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">產生對應固定大小的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Frame (</span></span><span style="font-size: x-small;">這會供</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik Register</span></span><span style="font-size: x-small;">使用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">). </span></span><span style="font-size: x-small;">每個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik Register</span></span><span style="font-size: x-small;">固定長度為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits,</span></span><span style="font-size: x-small;">相鄰的兩個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik Register</span></span><span style="font-size: x-small;">可以用來表示</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">64bits</span></span><span style="font-size: x-small;">的值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">函式如果有</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N</span></span><span style="font-size: x-small;">個參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在呼叫該函式時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">, </span></span><span style="font-size: x-small;">就會用到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register,</span></span><span style="font-size: x-small;">來作為該函式的呼叫之用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">而在函式內部的實作中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">也會用到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register</span></span><span style="font-size: x-small;">來操作所傳入的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N</span></span><span style="font-size: x-small;">個參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">只是上述的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N</span></span><span style="font-size: x-small;">個暫存器的對應</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在呼叫端與函式內部的實作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">不一定能直接對應</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">如果參數為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">64bits (</span></span><span style="font-size: x-small;">例如 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">double),</span></span><span style="font-size: x-small;">就會一次用到兩個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register</span></span><span style="font-size: x-small;">代表該</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">64bits</span></span><span style="font-size: x-small;">的函式參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">目前</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">所在的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class (</span></span><span style="font-size: x-small;">也就是</span><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">this),</span></span></code></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-size: x-small;">會是每個</span></code><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">Method</span></span></code></span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-size: x-small;">函式呼叫時的第一個參數</span></code><span style="font-family: "Times New Roman", serif;"><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">.</span></span></code></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">指令集中所帶的數值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">都固定為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">unsigned</span></span><span style="font-size: x-small;">型態</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">根據指令的不同</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">該指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">的描述中有的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Bits</span></span><span style="font-size: x-small;">可以被忽略</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">或是必須為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0.</span></span><span style="font-size: x-small;">對於透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits</span></span><span style="font-size: x-small;">暫存器進行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Mov</span></span><span style="font-size: x-small;">的資料</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">並不會去確認資料是整數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(int)</span></span><span style="font-size: x-small;">或是浮點數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(float). </span></span><span style="font-size: x-small;">站在指令集的角度</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">所對應的暫存器範圍不大於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">256(</span></span><span style="font-size: x-small;">也就是說最多會用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1bytes =8bits</span></span><span style="font-size: x-small;">去描述一個暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">最大定義到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0xff),</span></span><span style="font-size: x-small;">而有些</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16-bits</span></span><span style="font-size: x-small;">指令描述暫存器只會用到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4bits(</span></span><span style="font-size: x-small;">也就是說對這類指令暫存器最大只定義到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0f).</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">有些</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ByteCode</span></span><span style="font-size: x-small;">指令所參考的資料為不定長度的內容</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">這些資料所在記憶體位置必須是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4bytes Memory Alignment,</span></span><span style="font-size: x-small;">例如</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">:fill-array-data,</span></span><span style="font-size: x-small;">或</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">packed-switch,</span></span><span style="font-size: x-small;">在不足</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4bytes Alignment</span></span><span style="font-size: x-small;">的部份就會插入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits Nop </span></span><span style="font-size: x-small;">指令作為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Spacer,</span></span><span style="font-size: x-small;">如下例子</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0005: packed-switch v0, 00000012 // +0000000d</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><span style="text-decoration-line: underline;"><strong>=></strong></span></span></span><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>參考位於</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>12</strong></span></span></span><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>的資料</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>,</strong></span></span></span><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>由於要為</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>4bytes Alignment,</strong></span></span></span><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>所以在</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>11</strong></span></span></span><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>的位址插入</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>2bytes</strong></span></span></span><span style="text-decoration-line: underline;"><span style="font-size: xx-small;"><strong>的</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Spacer</strong></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">………………….</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">…………………..</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0011: nop // spacer</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0012: 0001 0200 1300 0000 0800 0000 0a00 … : packed-switch-data (8 units)</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">為解決原本</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java ByteCode</span></span><span style="font-size: x-small;">檔案格式中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">重複字串所導致的儲存空間浪費</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Dalvik Dex</span></span><span style="font-size: x-small;">檔案格式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會建置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">String ID,Type ID,Prototype ID,Field ID,Method ID</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class ID</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Tables,</span></span><span style="font-size: x-small;">只要有重複的字串</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">String ID</span></span><span style="font-size: x-small;">指到同一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Data</span></span><span style="font-size: x-small;">區塊中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">節省儲存空間</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">接下來讓我們以實際的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">程式碼</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik </span></span><span style="font-size: x-small;">與 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode,</span></span><span style="font-size: x-small;">比較其中實作的差異化</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">來了解兩者技術的不同</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">以下列程式碼為例</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>public</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>void</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Main1(</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> A)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">{</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><span style="text-decoration-line: underline;">vA</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><span style="text-decoration-line: underline;">vB</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vA=A;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vB=A*2;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">}</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">反組譯的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Dalvik ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">為</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000430: com.TestAA.TestAA.Main1:(I)V</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0000: [0130] move v0, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0001: [da01 0302] mul-int/lit8 v1, v3, #int 2 // #02</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0003: [0e00] return-void</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">其中</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">暫存器對應如下所示</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0001 – 0x0004 reg=0 vA I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0003 – 0x0004 reg=1 vB I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0000 – 0x0004 reg=2 this Lcom/TestAA/TestAA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0000 – 0x0004 reg=3 A I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">而同樣的程式碼</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">如果用</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Java ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">呈現如下</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0: iload_1 //load </span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">函式參數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">A</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">1: istore_2 //store </span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">到區域變數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">vA</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">2: iload_1 //load </span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">函式參數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">A</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">3: iconst_2 //</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">設定常數 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">2</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">4: imul //</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">把 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">A*2</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">5: istore_3 //store </span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">到區域變數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">vB</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">6: return //return void.</span></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">LocalVariableTable:</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Start Length Slot Name Signature</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0 7 0 this Lcom/TestAA/TestAA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0 7 1 A I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">2 5 2 vA I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">6 1 3 vB I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">我們可以看到</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Dalvik ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">的實作比較簡潔</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,Code Size</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">8bytes,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">總共用了三個指令</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">而原本</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Stack-Based</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Java ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">所需</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Code Size</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">7bytes,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">總共用了</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">7</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">個指令</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">需要比較多的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">load/store</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">動作</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">無法像是</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Dalvik Register-Based</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">的實作</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">以仿似一般處理器使用暫存器的方式</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">用三個指令就把原本</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Java</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">代碼中的邏輯完成</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">.</span></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">接下來</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">我們增加函式的參數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">並修改</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">return</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">值為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">int,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">如下程式碼</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>public</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Main2(</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> A,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> B)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">{</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vA=A;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vB=A*2+B;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>return</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vA+vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">}</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">反組譯的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Dalvik ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">為</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">000448: com.TestAA.TestAA.Main2:(II)I</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0000: [0140] move v0, v4</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0001: [da02 0402] mul-int/lit8 v2, v4, #int 2 // #02</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0003: [9001 0205] add-int v1, v2, v5</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0005: [9002 0001] add-int v2, v0, v1</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0007: [0f02] return v2</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">其中</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">暫存器對應如下所示</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0001 – 0x0008 reg=0 vA I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0005 – 0x0008 reg=1 vB I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0000 – 0x0008 reg=3 this Lcom/TestAA/TestAA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0000 – 0x0008 reg=4 A I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0x0000 – 0x0008 reg=5 B I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">而同樣的程式碼</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">如果用</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Java ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">呈現如下</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0: iload_1</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1: istore_3</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2: iload_1</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3: iconst_2</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">4: imul</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">5: iload_2</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">6: iadd</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">7: istore 4</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">9: iload_3</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">10: iload 4</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">12: iadd</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">13: ireturn</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">LocalVariableTable:</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Start Length Slot Name Signature</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 14 0 this Lcom/TestAA/TestAA;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 14 1 A I</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 14 2 B I</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2 12 3 vA I</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">9 5 4 vB I</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">接下來</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">我們把函式參數增為三個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">並修改</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">return</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">值為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">double,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">如下程式碼</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>public</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>double</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Main3(</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> A,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> B,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> C)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">{</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vA=A+3;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vB=A*2+B*3+C*4;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>return</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> (</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>double</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">)vA+vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">}</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">反組譯的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Dalvik ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">為</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000468: com.TestAA.TestAA.Main3:(III)D</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0000: [d800 0703] add-int/lit8 v0, v7, #int 3 // #03</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0002: [da02 0702] mul-int/lit8 v2, v7, #int 2 // #02</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0004: [da03 0803] mul-int/lit8 v3, v8, #int 3 // #03</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0006: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0007: [da03 0904] mul-int/lit8 v3, v9, #int 4 // #04</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0009: [9001 0203] add-int v1, v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000b: [8302] int-to-double v2, v0</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000c: [8314] int-to-double v4, v1</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000d: [cb42] add-double/2addr v2, v4</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000e: [1002] return-wide v2</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">而同樣的程式碼</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">如果用</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Java ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">呈現如下</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0: iload_1</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">1: iconst_3</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">2: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">3: istore 4</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">5: iload_1</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">6: iconst_2</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">7: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">8: iload_2</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">9: iconst_3</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">10: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">11: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">12: iload_3</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">13: iconst_4</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">14: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">15: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">16: istore 5</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">18: iload 4</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">20: i2d</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">21: iload 5</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">23: i2d</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">24: dadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">25: dreturn</span></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">接下來</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">我們把函式參數增為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">26</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">並修改</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">return</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">值為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">int,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">如下程式碼</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>public</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Main4(</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> A,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> B,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> C,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> D,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> E,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> F,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> G,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> H,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> I,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> J,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> K,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> L,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> M,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> N,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> O,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> P,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Q,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> R,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> S,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> T,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> U,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> V,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> W,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> X,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Y,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Z)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">{</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vA=A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vB=A*1+B*2+C*3+D*4+E*5+F*6+G*7+H*8+I*9+J*10+K*11+L*12+M*13+N*14+O*15+P*16+Q*17+R*18+S*19+T*20+U*21+V*22+W*23+X*24+Y*25+Z*26;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>return</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vA+vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">}</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">反組譯的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Dalvik ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">為</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000498: com.TestAA.TestAA.Main4:(IIIIIIIIIIIIIIIIIIIIIIIIII)I</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0000: [9002 0506] add-int v2, v5, v6</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0002: [b072] add-int/2addr v2, v7</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0003: [b082] add-int/2addr v2, v8</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0004: [b092] add-int/2addr v2, v9</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0005: [b0a2] add-int/2addr v2, v10</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0006: [b0b2] add-int/2addr v2, v11</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0007: [b0c2] add-int/2addr v2, v12</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0008: [b0d2] add-int/2addr v2, v13</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0009: [b0e2] add-int/2addr v2, v14</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000a: [b0f2] add-int/2addr v2, v15</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000b: [9002 0210] add-int v2, v2, v16</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000d: [9002 0211] add-int v2, v2, v17</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">000f: [9002 0212] add-int v2, v2, v18</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0011: [9002 0213] add-int v2, v2, v19</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0013: [9002 0214] add-int v2, v2, v20</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0015: [9002 0215] add-int v2, v2, v21</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0017: [9002 0216] add-int v2, v2, v22</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0019: [9002 0217] add-int v2, v2, v23</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">001b: [9002 0218] add-int v2, v2, v24</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">001d: [9002 0219] add-int v2, v2, v25</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">001f: [9002 021a] add-int v2, v2, v26</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0021: [9002 021b] add-int v2, v2, v27</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0023: [9002 021c] add-int v2, v2, v28</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0025: [9002 021d] add-int v2, v2, v29</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0027: [9000 021e] add-int v0, v2, v30</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0029: [da02 0501] mul-int/lit8 v2, v5, #int 1 // #01</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">002b: [da03 0602] mul-int/lit8 v3, v6, #int 2 // #02</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">002d: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">002e: [da03 0703] mul-int/lit8 v3, v7, #int 3 // #03</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0030: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0031: [da03 0804] mul-int/lit8 v3, v8, #int 4 // #04</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0033: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0034: [da03 0905] mul-int/lit8 v3, v9, #int 5 // #05</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0036: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0037: [da03 0a06] mul-int/lit8 v3, v10, #int 6 // #06</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0039: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">003a: [da03 0b07] mul-int/lit8 v3, v11, #int 7 // #07</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">003c: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">003d: [da03 0c08] mul-int/lit8 v3, v12, #int 8 // #08</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">003f: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0040: [da03 0d09] mul-int/lit8 v3, v13, #int 9 // #09</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0042: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0043: [da03 0e0a] mul-int/lit8 v3, v14, #int 10 // #0a</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0045: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0046: [da03 0f0b] mul-int/lit8 v3, v15, #int 11 // #0b</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0048: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0049: [da03 100c] mul-int/lit8 v3, v16, #int 12 // #0c</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">004b: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">004c: [da03 110d] mul-int/lit8 v3, v17, #int 13 // #0d</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">004e: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">004f: [da03 120e] mul-int/lit8 v3, v18, #int 14 // #0e</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0051: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0052: [da03 130f] mul-int/lit8 v3, v19, #int 15 // #0f</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0054: [b032]: add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0055: [da03 1410] mul-int/lit8 v3, v20, #int 16 // #10</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0057: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0058: [da03 1511] mul-int/lit8 v3, v21, #int 17 // #11</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">005a: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">005b: [da03 1612] mul-int/lit8 v3, v22, #int 18 // #12</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">005d: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">005e: [da03 1713] mul-int/lit8 v3, v23, #int 19 // #13</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0060: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0061: [da03 1814] mul-int/lit8 v3, v24, #int 20 // #14</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0063: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0064: [da03 1915] mul-int/lit8 v3, v25, #int 21 // #15</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0066: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0067: [da03 1a16] mul-int/lit8 v3, v26, #int 22 // #16</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0069: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">006a: [da03 1b17] mul-int/lit8 v3, v27, #int 23 // #17</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">006c: [b032] |: add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">006d: [da03 1c18] mul-int/lit8 v3, v28, #int 24 // #18</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">006f: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0070: [da03 1d19] mul-int/lit8 v3, v29, #int 25 // #19</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0072: [b032] add-int/2addr v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0073: [da03 1e1a] mul-int/lit8 v3, v30, #int 26 // #1a</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0075: [9001] [0203] add-int v1, v2, v3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0077: [9002 0001] add-int v2, v0, v1</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0079: [0f02] return v2</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">而同樣的程式碼</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">如果用</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Java ByteCode</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">呈現如下</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0: iload_1</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">1: iload_2</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">2: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">3: iload_3</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">4: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">5: iload 4</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">7: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">8: iload 5</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">10: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">11: iload 6</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">13: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">14: iload 7</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">16: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">17: iload 8</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">19: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">20: iload 9</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">22: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">23: iload 10</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">25: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">26: iload 11</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">28: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">29: iload 12</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">31: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">32: iload 13</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">34: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">35: iload 14</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">37: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">38: iload 15</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">40: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">41: iload 16</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">43: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">44: iload 17</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">46: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">47: iload 18</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">49: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">50: iload 19</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">52: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">53: iload 20</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">55: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">56: iload 21</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">58: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">59: iload 22</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">61: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">62: iload 23</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">64: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">65: iload 24</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">67: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">68: iload 25</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">70: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">71: iload 26</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">73: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">74: istore 27</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">76: iload_1</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">77: iconst_1</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">78: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">79: iload_2</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">80: iconst_2</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">81: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">82: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">83: iload_3</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">84: iconst_3</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">85: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">86: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">87: iload 4</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">89: iconst_4</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">90: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">91: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">92: iload 5</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">94: iconst_5</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">95: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">96: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">97: iload 6</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">99: bipush 6</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">101: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">102: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">103: iload 7</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">105: bipush 7</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">107: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">108: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">109: iload 8</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">111: bipush 8</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">113: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">114: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">115: iload 9</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">117: bipush 9</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">119: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">120: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">121: iload 10</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">123: bipush 10</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">125: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">126: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">127: iload 11</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">129: bipush 11</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">131: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">132: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">133: iload 12</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">135: bipush 12</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">137: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">138: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">139: iload 13</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">141: bipush 13</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">143: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">144: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">145: iload 14</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">147: bipush 14</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">149: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">150: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">151: iload 15</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">153: bipush 15</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">155: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">156: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">157: iload 16</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">159: bipush 16</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">161: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">162: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">163: iload 17</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">165: bipush 17</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">167: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">168: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">169: iload 18</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">171: bipush 18</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">173: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">174: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">175: iload 19</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">177: bipush 19</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">179: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">180: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">181: iload 20</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">183: bipush 20</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">185: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">186: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">187: iload 21</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">189: bipush 21</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">191: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">192: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">193: iload 22</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">195: bipush 22</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">197: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">198: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">199: iload 23</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">201: bipush 23</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">203: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">204: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">205: iload 24</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">207: bipush 24</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">209: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">210: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">211: iload 25</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">213: bipush 25</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">215: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">216: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">217: iload 26</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">219: bipush 26</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">221: imul</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">222: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">223: istore 28</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">225: iload 27</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">227: iload 28</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">229: iadd</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">230: ireturn</span></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;"></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">彙整上述四個函式的</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Java</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">與反組譯結果</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">我們可以發現</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">1, Dalvik</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">虛擬器所配置的暫存器個數會以資料總數為依據</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">每個暫存器寬度為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">32bits. </span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">且除函式參數與區域變數外</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">暫存器會配合執行需求重複利用</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">.</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">2, Dalvik</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">虛擬器暫存器並不像是</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">C</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">或是</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">ARM</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">原生程式一樣</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">有固定的函式參數推入的機制或是會使用的暫存器</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">(C</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">語言在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">X86</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Stack</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">由右往左推或是</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">ARM</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">用</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">R0-R3</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">暫存器來傳遞函式參數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">),</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">而是根據資料的長度決定</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #999999;"><span style="font-family: "Times New Roman", serif;">stackReq = method->registersSize * 4 // params + locals</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #999999;"><span style="font-family: "Times New Roman", serif;">+ sizeof(StackSaveArea) * 2 // break frame + regular frame</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #999999;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">+ method->outsSize * 4; // args to other methods</span></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>比較</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Stack-Based</strong></span></span><span style="font-size: small;"><strong>與</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Register-Based VM</strong></span></span><span style="font-size: small;"><strong>記憶體與指令實作的方式</strong></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">JDK</span></span><span style="font-size: x-small;">所編譯出來的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java Class</span></span><span style="font-size: x-small;">檔案</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會包含如下的資訊</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">LocalVariableTable:</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">Start Length Slot Name Signature</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0 38 0 this Lcom/testAA/testAA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0 38 1 A I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0 38 2 B I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">0 38 3 C I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">5 33 4 vA I</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: x-small;">18 20 5 vB I</span></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">用來描述每一個函式參數或區域變數對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中的位置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">以如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Main3 Method</span></span><span style="font-size: x-small;">時做為例</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>public</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>class</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> testAA </span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>extends</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Activity {</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="color: #0000c0;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">gA</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="color: #0000c0;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">gB</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">…..</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>public</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> </span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>double</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> Main3(</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> A,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> B,</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> C)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">{</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>int</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vA=A+3;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">vB=A*2+B*3+C*4;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #0000c0;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">gA</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">=vA;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #0000c0;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">gB</span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">=vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"></span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>return</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"> (</span></span><span style="color: #7f0055;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>double</strong></span></span></span><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">)vA+vB;</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">}</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">….</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;">}</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Main3</span></span><span style="font-size: x-small;">的呼叫端實作</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">double v3=Main3(111,222,333);</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">在呼叫端的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java ByteCode</span></span><span style="font-size: x-small;">實現為</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">27: aload_0</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">28: bipush 111</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">30: sipush 222</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">33: sipush 333</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">36: invokevirtual #62; //Method Main3:(III)D</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">39: dstore_3</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">我們可以看到參數由左往右推入堆疊中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">參照</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中的位置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">可以看到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame Slot 0</span></span><span style="font-size: x-small;">會擺放函式參數的第一個變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">也就是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">本身 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">this),</span></span><span style="font-size: x-small;">依此類推把函式參數放置完後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">再配置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">中對應的區域變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">同樣由宣告的順序開始擺放到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame Slot</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">每個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Slot</span></span><span style="font-size: x-small;">中所包含的變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">都會包含該變數對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">所需存在的行數起點與終點</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">參考上述 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">LocalVariableTable</span></span><span style="font-size: x-small;">的描述</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Slot 1 (</span></span><span style="font-size: x-small;">函式參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">A)</span></span><span style="font-size: x-small;">會在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span><span style="font-size: x-small;">行前存在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">38</span></span><span style="font-size: x-small;">行結束使用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0: iload_1</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1: iconst_3</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">…..</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">36: dadd</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">37: dreturn</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">或根據 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">LocalVariableTable</span></span><span style="font-size: x-small;">描述</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Slot 4 (</span></span><span style="font-size: x-small;">區域變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">vA)</span></span><span style="font-size: x-small;">會在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">5</span></span><span style="font-size: x-small;">行前存在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">38</span></span><span style="font-size: x-small;">行結束使用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">…..</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">3: istore 4</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">5: iload_1</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">….</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">30: iload 4</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32: i2d</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">33: iload 5</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">35: i2d</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">36: dadd</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">37: dreturn</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Slot 5 (</span></span><span style="font-size: x-small;">區域變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">vB)</span></span><span style="font-size: x-small;">會在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">18</span></span><span style="font-size: x-small;">行前存在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">38</span></span><span style="font-size: x-small;">行結束使用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">………………..</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16: istore 5</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">18: aload_0</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">19: iload 4</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">……………….</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32: i2d</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">33: iload 5</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">35: i2d</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">36: dadd</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">37: dreturn</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">如下所示對</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">內部變數的寫入是透過指令 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">putfield,</span></span><span style="font-size: x-small;">先把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">本身推入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack,</span></span><span style="font-size: x-small;">再把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">vA (Slot4)</span></span><span style="font-size: x-small;">值推入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack,</span></span><span style="font-size: x-small;">之後透過 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">” putfield #27″,</span></span><span style="font-size: x-small;">把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">vA</span></span><span style="font-size: x-small;">寫入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Constant pool Index=27</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">18: aload_0</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">19: iload 4</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">21: putfield #27; //Field gA:I</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">最後會呼叫</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dreturn,</span></span><span style="font-size: x-small;">把返回的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">double</span></span><span style="font-size: x-small;">數值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">從目前所在的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中取出</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">放到呼叫端的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">回到呼叫端後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">再呼叫</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dstore</span></span><span style="font-size: x-small;">從呼叫端的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中放到呼叫端對應變數所在的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Slot</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">藉由上述說明</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們可以了解</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java</span></span><span style="font-size: x-small;">對函式參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">區域變數與返回值對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中的操作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">接下來讓我們比對</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">在這部份的記憶體行為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">首先</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們可以看到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Main3</span></span><span style="font-size: x-small;">會具備如下的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Locals Table</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">locals :</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0002 – 0x0013 reg=0 vA I</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000b – 0x0013 reg=1 vB I</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0013 reg=6 this Lcom/testAA/testAA;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0013 reg=7 A I</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0013 reg=8 B I</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0013 reg=9 C I</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">在對應到呼叫端的實作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">00060a: 1304 6f00 |001f: const/16 v4, #int 111 // #6f</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">00060e: 1305 de00 |0021: const/16 v5, #int 222 // #de</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">000612: 1306 4d01 |0023: const/16 v6, #int 333 // #14d</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">000616: 0800 2400 |0025: move-object/from16 v0, v36</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">00061a: 0141 |0027: move v1, v4</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">00061c: 0152 |0028: move v2, v5</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">00061e: 0163 |0029: move v3, v6</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">000620: f840 fb00 1032 |002a: +invoke-virtual-quick {v0, v1, v2, v3}, [00fb] // vtable #00fb</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">000626: 0b20 |002d: move-result-wide v32</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">同樣的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Dalvik</span></span><span style="font-size: x-small;">中會去描述每一個暫存器在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ByteCode</span></span><span style="font-size: x-small;">行數所存在的範圍</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">並不是每個區域變數都會從頭到尾被需要</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span><span style="font-size: x-small;">同時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在寫入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">內部的變數時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">則是透過指令 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">iput-quick</span></span><span style="font-size: x-small;">操作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">[f560 b000] +iput-quick v0, v6, [obj+00b0]</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">[f561 b400] +iput-quick v1, v6, [obj+00b4]</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">我們可以看到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會從右到左為順序去把參數推到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">也可以參考指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">OP_INVOKE_VIRTUAL_QUICK</span></span><span style="font-size: x-small;">的實作流程</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.),</span></span><span style="font-size: x-small;">也因此</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">指到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">本身的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">this,</span></span><span style="font-size: x-small;">會變成是最靠區域變數的最後一個函式參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">並以此去對應到被呼叫函式中所對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register</span></span><span style="font-size: x-small;">編號</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">區域變數則由最後宣告的變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">放在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register</span></span><span style="font-size: x-small;">最大值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">最先宣告的區域變數對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register</span></span><span style="font-size: x-small;">最小值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">從</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">暫存器對應到記憶體的角度來看</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">其實這跟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java</span></span><span style="font-size: x-small;">把函式參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">區域變數跟返回值對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame Slot</span></span><span style="font-size: x-small;">的意義是一樣的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">雖然</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">指令最多可以定址到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">256</span></span><span style="font-size: x-small;">個暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">但這些暫存器在記憶體中儲存的位置還是對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">同樣的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java</span></span><span style="font-size: x-small;">實作中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果今天有數量較多的區域變數或是函式參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">一樣都是對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Slot,</span></span><span style="font-size: x-small;">這就如同</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">是對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Frame</span></span><span style="font-size: x-small;">中對應的暫存器位置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">每個都是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32-bits)</span></span><span style="font-size: x-small;">在操作與記憶體成本上是可以一致的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">不過我沒看過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java</span></span><span style="font-size: x-small;">的實作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Source Code,</span></span><span style="font-size: x-small;">只是從反組譯與行為來推測</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">).</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">從</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Based</span></span><span style="font-size: x-small;">實作虛擬器的角度來看</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">最大的效能改善應該不是來自於記憶體或是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stake Frame</span></span><span style="font-size: x-small;">的改善</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">而是來自於要達到同樣目的時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Register Based</span></span><span style="font-size: x-small;">指令集可以比</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack Based</span></span><span style="font-size: x-small;">虛擬器指令集更加的精簡 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">前提是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Android DX</span></span><span style="font-size: x-small;">也要能產生出對應有效率的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java ByteCode -> Dalvik ByteCode</span></span><span style="font-size: x-small;">轉譯</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">真的發揮</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Based</span></span><span style="font-size: x-small;">虛擬器的優勢</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">),</span></span><span style="font-size: x-small;">舉如下的例子來說</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">如果要把值寫入到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">中的變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">gA,</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java ByteCode</span></span><span style="font-size: x-small;">實作為</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">aload_0</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">iload 4</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">putfield #27; //Field gA:I</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">共三個指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">而在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ByteCode</span></span><span style="font-size: x-small;">中只要一個指令就好</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">iput-quick v0, v6, [obj+00b0]</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">同樣的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果要做區域變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">vA</span></span><span style="font-size: x-small;">等於函式參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">A</span></span><span style="font-size: x-small;">的動作 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">“vA=A”,</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java ByteCode</span></span><span style="font-size: x-small;">實作為</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">iload_1 (Load A to Stack Frame)</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">istore_3 (Store value from Stack Frame to vA)</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">共</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2</span></span><span style="font-size: x-small;">個指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">而在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ByteCode</span></span><span style="font-size: x-small;">中只要一個指令就好</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">move v0, v4 //v0=vA and v4=A</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">我們可以看到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register-Based</span></span><span style="font-size: x-small;">在指令集的效率上可以比較高</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">效能的好壞會在於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Android</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">實作的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DX</span></span><span style="font-size: x-small;">轉譯工具</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">這工具如何把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java ByteCode</span></span><span style="font-size: x-small;">轉譯為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ByteCode,</span></span><span style="font-size: x-small;">會不會有其他如本文之前所提到的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">產生出沒有效率的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ByteCode</span></span><span style="font-size: x-small;">代碼</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會是影響</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Android</span></span><span style="font-size: x-small;">執行效率的關鍵</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">雖然</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ByteCode</span></span><span style="font-size: x-small;">最小成本為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits,</span></span><span style="font-size: x-small;">比起</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun Java ByteCode</span></span><span style="font-size: x-small;">最小可以為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">8bits</span></span><span style="font-size: x-small;">高</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">但實際上以目前</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">處理器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Bus</span></span><span style="font-size: x-small;">與對外部記憶體的寬度至少都是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32-bits</span></span><span style="font-size: x-small;">來看</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">存取一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">跟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">8bits</span></span><span style="font-size: x-small;">值對</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">External Memory Bus</span></span><span style="font-size: x-small;">成本基本上是一樣的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">減少指令的用量</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">應該會比減少指令長度來的對效能有所助益</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Register Map Area</strong></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DEX</span></span><span style="font-size: x-small;">檔案中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會有每一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">實作時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">所需用到的暫存器數量</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">函式參數總數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">用來呼叫其它函式所用到的暫存器總數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">與指令集總個數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16bits</span></span><span style="font-size: x-small;">為單位</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">),</span></span><span style="font-size: x-small;">格式如下所示</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">registers : 10 </span><span style="font-size: xx-small;"><strong>(</strong></span></span><span style="font-size: xx-small;"><strong>包含函式參數</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>,</strong></span></span><span style="font-size: xx-small;"><strong>區域變數與中間資料搬移時所會用到的暫存器個數加總</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>)</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ins : 4 </span><span style="font-size: xx-small;"><strong>(Method</strong></span></span><span style="font-size: xx-small;"><strong>函式參數用到的暫存器個數 </strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>=></strong></span></span><span style="font-size: xx-small;"><strong>都會加上第一個參數指到</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Class Object </strong></span></span><span style="font-size: xx-small;"><strong>本身</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>)</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">outs : 3 </span><span style="font-size: xx-small;"><strong>(Method </strong></span></span><span style="font-size: xx-small;"><strong>中呼叫其它函式所用到的暫存器總數</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>)</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">insns size : 31 16-bit code units </span><span style="font-size: xx-small;"><strong>(</strong></span></span><span style="font-size: xx-small;"><strong>以</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>16bits</strong></span></span><span style="font-size: xx-small;"><strong>為單位</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>,</strong></span></span><span style="font-size: xx-small;"><strong>統計這個</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Method</strong></span></span><span style="font-size: xx-small;"><strong>所佔用的指令總長度</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>)</strong></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">虛擬器一個最大的特徵就是不同於過去其他</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java VM</span></span><span style="font-size: x-small;">為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Stack-based</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">VM,</span></span><span style="font-size: x-small;">它是一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register-based</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">VM,</span></span><span style="font-size: x-small;">在對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">處理器的實作時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">可以透過原生處理器的暫存器進行優化</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">同時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik ARM</span></span><span style="font-size: x-small;">的實作中有些</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">處理器暫存器已經被</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik </span></span><span style="font-size: x-small;">虛擬器本身</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,gcc</span></span><span style="font-size: x-small;">編譯器或是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Calling Convention</span></span><span style="font-size: x-small;">所使用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如下就列出有被指定使用的暫存器儘供參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 808px;"><colgroup><col width="145"></col><col width="80"></col><col width="551"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td height="1" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-family: tahoma, arial;"><span style="font-size: x-small;">暫存器</span></span><span style="font-size: x-small;"></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: tahoma, arial;"><span style="font-size: x-small;">識別名稱</span></span><span style="font-size: x-small;"></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: tahoma, arial;"><span style="font-size: x-small;">說明</span></span><span style="font-size: x-small;"></span></td></tr>
<tr valign="TOP"><td bgcolor="#ffff00" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="color: #ff3366;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>R0/R1/R2/R3/R9/R10</strong></span></span></span></td><td bgcolor="#ffff00" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"></td><td bgcolor="#ffff00" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-size: xx-small;">這</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">6</span></span><span style="font-size: xx-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM</span></span><span style="font-size: xx-small;">暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">是在實現</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Dalvik</span></span><span style="font-size: xx-small;">指令時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">,</span></span><span style="font-size: xx-small;">會被使用的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM</span></span><span style="font-size: xx-small;">暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">.</span></span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R4</span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">rPC</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">interpreted program counter, used for fetching instructions</span></span><span style="font-size: xx-small;"> (Dalvik</span></span><span style="font-size: xx-small;">預定用途</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">)</span></span></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R5</span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">rFP</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">interpreted frame pointer, used for accessing locals and args</span></span><span style="font-size: xx-small;"> (Dalvik</span></span><span style="font-size: xx-small;">預定用途</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">)</span></span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R6</span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">rGLUE</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">MterpGlue pointer</span></span><span style="font-size: xx-small;"> (Dalvik</span></span><span style="font-size: xx-small;">預定用途</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">)</span></span></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R7</span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">rINST</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">first 16-bit code unit of current instruction</span></span><span style="font-size: xx-small;"> (Dalvik</span></span><span style="font-size: xx-small;">預定用途</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">)</span></span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R8</span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">rIBASE</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">interpreted instruction base pointer, used for computed goto</span></span><span style="font-size: xx-small;"> (Dalvik</span></span><span style="font-size: xx-small;">預定用途</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">)</span></span></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R11</span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">fp</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">Used by gcc (unless -fomit-frame-pointer is set)</span></span><span style="font-size: xx-small;"></span></span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R12</span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">ip</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">ARM Intra-Procedure-call scratch register</span></span></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R13</span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">sp</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM Stack Pointer</span></span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R14</span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">lr</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">ARM Link Register</span></span></td></tr>
<tr valign="TOP"><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R15</span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;"><span style="font-family: tahoma, arial;"><span style="font-size: xx-small;">pc</span></span><span style="font-size: xx-small;"></span></span></td><td bgcolor="#b3b3b3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="551"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM Program Counter</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik </span></span><span style="font-size: x-small;">虛擬器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">主要會讓虛擬器的暫存器與資料對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">R0,R1,R2,R3,R9</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">R12</span></span><span style="font-size: x-small;">共</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">6</span></span><span style="font-size: x-small;">個暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">作為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik Register-Based</span></span><span style="font-size: x-small;">虛擬器執行與加速之用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span><span style="font-size: x-small;">可參考如下例子</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.L_OP_CONST_WIDE: /* 0x18 */</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">/* File: armv5te/OP_CONST_WIDE.S */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">/* const-wide vAA, #+HHHHhhhhBBBBbbbb */</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FETCH(r0, 1) @ r0<- bbbb (low)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FETCH(r1, 2) @ r1<- BBBB (low middle)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FETCH(r2, 3) @ r2<- hhhh (high middle)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">orr r0, r0, r1, lsl #16 @ r0<- BBBBbbbb (low word)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FETCH(r3, 4) @ r3<- HHHH (high)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">mov r9, rINST, lsr #8 @ r9<- AA</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">orr r1, r2, r3, lsl #16 @ r1<- HHHHhhhh (high word)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FETCH_ADVANCE_INST(5) @ advance rPC, load rINST</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">add r9, rFP, r9, lsl #2 @ r9<- &fp[AA]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">GET_INST_OPCODE(ip) @ extract opcode from rINST</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">stmia r9, {r0-r1} @ vAA<- r0/r1</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">GOTO_OPCODE(ip) @ jump to next instruction</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>基本的<span style="font-family: "Times New Roman", serif;">DEX</span>檔案中會包括如下的<span style="font-family: "Times New Roman", serif;">Register</span>對應到行數存在的範圍<span style="font-family: "Times New Roman", serif;">,</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">com.testAA.testAA.MainX:(I)V</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0000: [0130] move v0, v3</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0001: [da01 0302] mul-int/lit8 v1, v3, #int 2 // #02</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0003: [f520 b000] +iput-quick v0, v2, [obj+00b0]</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0005: [f521 b400] +iput-quick v1, v2, [obj+00b4]</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0007: [0e00] return-void</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">locals :</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x0001 – 0x0008 reg=0 vA I</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x0003 – 0x0008 reg=1 vB I</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x0000 – 0x0008 reg=2 this Lcom/testAA/testAA;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x0000 – 0x0008 reg=3 A I</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>這會表示<span style="font-family: "Times New Roman", serif;">,</span>暫存器<span style="font-family: "Times New Roman", serif;">v0</span>對應到區域變數<span style="font-family: "Times New Roman", serif;">vA,</span>存在範圍從<span style="font-family: "Times New Roman", serif;">1-8 ByteCode</span>指令行數<span style="font-family: "Times New Roman", serif;">.</span>而<span style="font-family: "Times New Roman", serif;">v3</span>對應到函式參數<span style="font-family: "Times New Roman", serif;">A,</span>存在範圍從<span style="font-family: "Times New Roman", serif;">0-8 ByteCode</span>指令行數<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">為了達到更有效率的系統加速</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Dalvik</span></span><span style="font-size: x-small;">提供了針對處理器的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">機制</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">主要是在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dex</span></span><span style="font-size: x-small;">檔案進行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Verification</span></span><span style="font-size: x-small;">時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">同步的根據每個指令集的行為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">對應到目前要執行的處理器的暫存器使用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">使得最後在運作時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">相關的變數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Method</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">都已經根據暫存器的使用與長度而有對應的排列</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">因為是在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Verification</span></span><span style="font-size: x-small;">中進行的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">也就是說只有</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ODEX</span></span><span style="font-size: x-small;">檔案格式中才會包含這個區塊</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Android</span></span><span style="font-size: x-small;">的文件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">有加入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">資訊的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ODEX</span></span><span style="font-size: x-small;">檔案</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">可能會比原本的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DEX</span></span><span style="font-size: x-small;">檔案多出</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">25%</span></span><span style="font-size: x-small;">的儲存需求</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">也因此</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Android</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dalvik/vm/analysis/RegisterMap.c</span></span><span style="font-size: x-small;">中其實也有實作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">JIT</span></span><span style="font-size: x-small;">版本的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map,</span></span><span style="font-size: x-small;">以便搭配</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Trace-JIT</span></span><span style="font-size: x-small;">的機制</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">既希望可以達到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">的目標</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">又希望可以達到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Trace-JIT</span></span><span style="font-size: x-small;">節省記憶體需求的優勢</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">目前已筆者手中的程式碼來看</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">這個機制目前尚未啟用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">且也有可能</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Android</span></span><span style="font-size: x-small;">未來會移除這部份的程式碼實作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">如果</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik VM</span></span><span style="font-size: x-small;">在啟動時有加上 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">“-Xgenregmap”</span></span><span style="font-size: x-small;">參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">之後在進行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DEX</span></span><span style="font-size: x-small;">檔案的最佳化時就會呼叫函式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dvmGenerateRegisterMaps (</span></span><span style="font-size: x-small;">實作在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dalvik/vm/analysis/RegisterMap.c),</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ODEX</span></span><span style="font-size: x-small;">檔案中產生</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap,</span></span><span style="font-size: x-small;">執行中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會先配置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4MB</span></span><span style="font-size: x-small;">的記憶體區塊</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">然後呼叫函式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">writeMapsAllClasses,writeMapsAllMethods,writeMapForMethod,computeRegisterMapSize</span></span><span style="font-size: x-small;">產生</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">資訊</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dalvik/vm/analysis/RegisterMap.c</span></span><span style="font-size: x-small;">中函式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dvmGenerateRegisterMapV</span></span><span style="font-size: x-small;">的實作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">regWidth = (vdata->method->registersSize + 7) / 8;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">regWidth</span></span><span style="font-size: x-small;">長度每一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">bit</span></span><span style="font-size: x-small;">都會對應到每一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">中所用到的暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">如果</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">一個函式用到四個暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(V0,V1,V2</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">V3),</span></span><span style="font-size: x-small;">其中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">V1</span></span><span style="font-size: x-small;">跟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">V3</span></span><span style="font-size: x-small;">屬於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegTypeUninit,</span></span><span style="font-size: x-small;">在第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span><span style="font-size: x-small;">行會用到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">V1,</span></span><span style="font-size: x-small;">此時的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap</span></span><span style="font-size: x-small;">內容值會為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">b0010=0x02 (bit 1</span></span><span style="font-size: x-small;">會設為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1). </span></span><span style="font-size: x-small;">在第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4</span></span><span style="font-size: x-small;">行會用到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">V3,</span></span><span style="font-size: x-small;">則</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap</span></span><span style="font-size: x-small;">會為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">b1010=0x0a (bit 1</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">bit3</span></span><span style="font-size: x-small;">會設為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1),</span></span><span style="font-size: x-small;">目前</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap</span></span><span style="font-size: x-small;">會根據所用到的暫存器順序</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">regWidth</span></span><span style="font-size: x-small;">長度</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(in bytes)</span></span><span style="font-size: x-small;">中每一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">bit</span></span><span style="font-size: x-small;">值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">設定為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">bit,</span></span><span style="font-size: x-small;">所對應的暫存器值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會是需要在運作時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">進行初始化的暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">此外</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在設定</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dalvik.vm.dexopt-flags </span></span><span style="font-size: x-small;">時加入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">m=y,</span></span><span style="font-size: x-small;">也可以開啟 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">最佳化參數</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">setprop dalvik.vm.dexopt-flags v=a,o=v,m=y</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">或是把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dalvik.vm.dexopt-flags= v=a,o=v,m=y </span></span><span style="font-size: x-small;">加入到開機</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Property</span></span><span style="font-size: x-small;">參數檔中亦可</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">)</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">主要用來表示哪一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Type</span></span><span style="font-size: x-small;">屬於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegTypeUninit</span></span><span style="font-size: x-small;">或是大於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegTypeMAX(</span></span><span style="font-size: x-small;">實作程式碼可以參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">dalvik/vm/analysis/RegisterMap.c</span></span><span style="font-size: x-small;">中的函式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">outputTypeVector),</span></span><span style="font-size: x-small;">在實際的執行上</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">例如以下的暫存器會屬於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegTypeUninit. (Uninitial–</span></span><span style="font-size: x-small;">在執行時期才指定對應的值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1,</span></span><span style="font-size: x-small;">對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Object</span></span><span style="font-size: x-small;">所用到的暫存器</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2,Return Class Object</span></span><span style="font-size: x-small;">所用到的暫存器</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">舉實際的例子來說</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">com.htc.android.worldclock.widget.NumberTableView.TableAdapter.getItem:(I)Ljava/lang/Object;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0000:invoke-static {v2}, Ljava/lang/Integer;.valueOf:(I)Ljava/lang/Integer; // method@0a4e</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0003:move-result-object v0</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0004:return-object v0</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">locals :</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0005 reg=1 this Lcom/htc/android/worldclock/widget/NumberTableView$TableAdapter;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0005 reg=2 position I</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">由於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v1</span></span><span style="font-size: x-small;">暫存器符合條件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">所以第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span><span style="font-size: x-small;">行的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">b0010=0x02</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">由於第四行透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v0</span></span><span style="font-size: x-small;">返回</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">物件參考且</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v1</span></span><span style="font-size: x-small;">符合條件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">所以第四行的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">b0011=0x03</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">結果如下</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">#1: 0x00061628 getItem</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0: 02</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4: 03</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><br /></span></span><span style="font-size: x-small;">再舉如下的例子來說明</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">com.htc.android.worldclock.widget.MyScrollView.<init>:(Landroid/content/Context;Landroid/util/AttributeSet;)V</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0000: const/4 v0, #int 0 // #0</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0001: invoke-direct {v1, v2, v3, v0}, Lcom/htc/android/worldclock/widget/MyScrollView;.<init>:(Landroid/content/Context;Landroid/util/AttributeSet;I)V // method@0902</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0004: return-void</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">locals :</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0005 reg=1 this Lcom/htc/android/worldclock/widget/MyScrollView;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0005 reg=2 context Landroid/content/Context;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0005 reg=3 attrs Landroid/util/AttributeSet;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v1,v2,v3</span></span><span style="font-size: x-small;">都指向對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Object</span></span><span style="font-size: x-small;">而返回值為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">void,</span></span><span style="font-size: x-small;">所以行數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4</span></span><span style="font-size: x-small;">對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">b1110=0x0e</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">結果如下</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">#1: 0x00061564 <init></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1: 0e</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4: 0e</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">再舉如下的例子來說明</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">com.htc.android.worldclock.TimeZonePicker.SimpleSearchModule.access$1300:(Lcom/htc/android/worldclock/TimeZonePicker$SimpleSearchModule;Ljava/lang/String;)Landroid/database/Cursor;</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0000: invoke-direct {v1, v2}, Lcom/htc/android/worldclock/TimeZonePicker$SimpleSearchModule;.coreSearch:(Ljava/lang/String;)Landroid/database/Cursor; // method@06fc</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0003: move-result-object v0</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0004: return-object v0</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">locals :</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0005 reg=1 x0 Lcom/htc/android/worldclock/TimeZonePicker$SimpleSearchModule;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x0000 – 0x0005 reg=2 x1 Ljava/lang/String;</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v1</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v2</span></span><span style="font-size: x-small;">暫存器符合條件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">都指向對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Object,</span></span><span style="font-size: x-small;">所以第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span><span style="font-size: x-small;">行的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">b0110=0x06</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">由於第四行透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v0</span></span><span style="font-size: x-small;">返回</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">物件參考且</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v1</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">v2</span></span><span style="font-size: x-small;">符合條件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">所以第四行的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">RegisterMap</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">b0111=0x07</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">結果如下</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">#1: 0x0005fad8 access$1300</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0: 06</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4: 07</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">由上述舉例</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們可以知道</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">可以表示每一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class</span></span><span style="font-size: x-small;">中的每一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">所用到的暫存器有哪一個是尚未被初始化而必須要在執行階段解決</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Object</span></span><span style="font-size: x-small;">相對位址的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">藉此可以在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Dalvik</span></span><span style="font-size: x-small;">虛擬器載入</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DEX</span></span><span style="font-size: x-small;">檔案執行時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">透過 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Regfister Map</span></span><span style="font-size: x-small;">知道每一個函式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method</span></span><span style="font-size: x-small;">中對應的哪一個暫存器是需要在執行階段解決對應位置的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">藉此讓虛擬器可以在執行階段優化處理</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">加速執行的效率</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register Map</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Optimized DEX</span></span><span style="font-size: x-small;">檔案中的資料格式為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">有關</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Virtual Method</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Direct Method</span></span><span style="font-size: x-small;">分別的總數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Class Definition</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">classDataOff</span></span><span style="font-size: x-small;">值</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">對應到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">struct DexClassDataHeader</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">virtualMethodsSize</span></span><span style="font-size: x-small;">與 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">directMethodsSize</span></span><span style="font-size: x-small;">取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">)</span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 808px;"><colgroup><col width="79"></col><col width="296"></col><col width="401"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="79"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
欄位屬性</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
長度</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr valign="TOP"><td rowspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="79"><span style="font-family: "Times New Roman", serif;">Class and Method Information</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;">4bytes</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;">Number of Classes</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;">4bytes * Number of Classes</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;">Classes Data Offset</span></td></tr>
<tr valign="TOP"><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="706">…<span style="font-family: "Times New Roman", serif;">……….</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">……………………. (4 bytes Class Offset)……</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…<span style="font-family: "Times New Roman", serif;">………..</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2 bytes</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Method Count for the Class</span></span><span style="font-size: x-small;">包含</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Direct Methods</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Virtual Methods</span></span><span style="font-size: x-small;">的總數 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">不超過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2^16)</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2 bytes</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">two pad bytes follow methodCount</span></span></td></tr>
<tr class="alt" valign="TOP"><td rowspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="79"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Direct Methods</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 byte</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Direct Methods RegMapFormat</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegMapFormatNone (</span><span style="font-size: x-small;">addrWidth = 0;)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegMapFormatCompact8 (</span><span style="font-size: x-small;">addrWidth = 1;)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegMapFormatCompact16 (</span><span style="font-size: x-small;">addrWidth = 2;)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegMapFormatDifferential</span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 byte</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">regWidth</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2 byte</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NumEntries (</span></span><span style="font-size: x-small;">不超過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2^16)</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 , 1 or 2 bytes</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-size: x-small;">指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Address (</span></span><span style="font-size: x-small;">以 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">addrWidth</span></span><span style="font-size: x-small;">為依據</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">)</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 bytes * regWidth</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register </span></span><span style="font-size: x-small;">長度</span></td></tr>
<tr valign="TOP"><td rowspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="79"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Virtual Methods</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 byte</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Virtual Methods RegMapFormat</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegMapFormatNone (</span><span style="font-size: x-small;">addrWidth = 0;)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegMapFormatCompact8 (</span><span style="font-size: x-small;">addrWidth = 1;)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegMapFormatCompact16 (</span><span style="font-size: x-small;">addrWidth = 2;)</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">kRegMapFormatDifferential</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 byte</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">regWidth</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2 byte</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NumEntries (</span></span><span style="font-size: x-small;">不超過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2^16)</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 , 1 or 2 bytes</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-size: x-small;">指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Address (</span></span><span style="font-size: x-small;">以 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">addrWidth</span></span><span style="font-size: x-small;">為依據</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">)</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="296"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 bytes * regWidth</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="401"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Register </span></span><span style="font-size: x-small;">長度</span></td></tr>
</tbody></table>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Dex</strong></span></span><span style="font-size: small;"><strong>檔案的資料型態</strong></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">LEB128(Little-Endian Base 128) </span></span>是一個可將<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">signed</span></span>與<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">unsigned 32bits</span></span>整數資料編碼為可變長度資料的格式<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">,</span></span>主要是參考<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">DWARF3(</span></span>除錯檔案格式<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">)</span></span>的標準而來<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">(</span></span>參考網址<span style="font-family: "Times New Roman", serif;"><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://dwarfstd.org/Dwarf3Std.php" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-family: sans-serif, Arial;">http://dwarfstd.org/Dwarf3Std.php</span></a></span></span><span style="font-family: sans-serif, Arial;"> ). </span></span>每一個<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">LEB128</span></span>編碼的資料長度可為<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">1</span></span>到<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">5bytes,</span></span>用以表示一個<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">32-bits</span></span>的整數值<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">.</span></span>對<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">singed LEB128</span></span>來說<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">,</span></span>最後一個<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">bytes,</span></span>的最高<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">bit</span></span>會用來表示該<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">32-bits</span></span>值的正負<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"></span></span><span style="font-size: x-small;">以如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">2bytes </span></span><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Unsigned LEB128</span></span></span><span style="font-size: x-small;">數值為例</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0x90 20</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="39"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="41"></col></colgroup><tbody>
<tr class="alt"><td colspan="16" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="TOP" width="793"><span style="font-family: "Times New Roman", serif;">Bitwise diagram of a two-byte LEB128 value</span></td></tr>
<tr valign="TOP"><td bgcolor="#ffffff" colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">First Byte</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="392"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Second Byte</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="39"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit6</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit5</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit4</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit3</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit13</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit12</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit11</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit10</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit9</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit8</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit7</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x90 & 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">2</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x20 & 0x80 </span></span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">所以</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Unsigned LEB128</span></span></span><span style="font-size: x-small;">結果為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0x90&0x7f + (0x20&0x7f) <<7 = 0x1010</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">以如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">3 bytes Unsigned LEB128</span></span></span><span style="font-size: x-small;">數值為例</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0xd4 df 04</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="22"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="24"></col></colgroup><tbody>
<tr><td colspan="24" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="TOP" width="793"><span style="font-family: "Times New Roman", serif;">Bitwise diagram of a three-byte LEB128 value</span></td></tr>
<tr class="alt" valign="TOP"><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">First Byte</span></span></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="258"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Second Byte</span></span></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="259"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Third Byte</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="22"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit6</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit5</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit4</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit3</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit13</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit12</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit11</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit10</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit9</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit8</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit7</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit20</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit19</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit18</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit17</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit16</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit15</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit14</span></span></td></tr>
</tbody></table>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0xd4 & 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">2</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0xdf & 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">3</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x04 & 0x80 </span></span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">所以</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Unsigned LEB128</span></span></span><span style="font-size: x-small;">結果為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0xd4&0x7f + (0xdf&0x7f) <<7 + (0x04&0x7f) <<14= 0x012fd4</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">以如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">4 bytes Unsigned LEB128</span></span></span><span style="font-size: x-small;">數值為例</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0xb8 84 80 01</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="14"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="15"></col><col width="16"></col></colgroup><tbody>
<tr class="alt"><td colspan="32" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="TOP" width="793"><span style="font-family: "Times New Roman", serif;">Bitwise diagram of a fourth-byte LEB128 value</span></td></tr>
<tr valign="TOP"><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">First Byte</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Second Byte</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Third Byte</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="192"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Fourth Byte</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit6</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit5</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit4</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit3</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit13</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit12</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit11</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit10</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit9</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit8</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit7</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit20</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit19</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit18</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit17</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit16</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit15</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit14</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit27</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit26</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit25</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit24</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit23</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit22</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="16"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit21</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0xb8 & 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">2</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x84& 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">3</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x80 & 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">4</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x01 & 0x80 </span></span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">所以</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Unsigned LEB128</span></span></span><span style="font-size: x-small;">結果為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0xb8&0x7f + (0x84&0x7f) <<7 + (0x80&0x7f) <<14 + (0x01&0x7f) <<21 = 0x200238</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"></span></span><span style="font-size: x-small;">以如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1 bytes Signed LEB128</span></span></span><span style="font-size: x-small;">數值為例</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0x1c</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x1c & 0x80 </span></span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">所以</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Signed LEB128</span></span></span><span style="font-size: x-small;">結果為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">((0x1c&0x7f )<< 25) >> 25 = 0x1c</span></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">以如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">2 bytes Signed LEB128</span></span></span><span style="font-size: x-small;">數值為例</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0x8e 04</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="39"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="40"></col><col width="41"></col></colgroup><tbody>
<tr><td colspan="16" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="TOP" width="793"><span style="font-family: "Times New Roman", serif;">Bitwise diagram of a two-byte LEB128 value</span></td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#ffffff" colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">First Byte</span></span></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="392"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Second Byte</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="39"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit6</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit5</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit4</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit3</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit13</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit12</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit11</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit10</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit9</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="40"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit8</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit7</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x8e & 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">2</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x04 & 0x80 </span></span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">所以</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Signed LEB128</span></span></span><span style="font-size: x-small;">結果為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">((0x8e&0x7f + (0x04&0x7f) <<7)<< 18) >> 18 = 0x020e</span></span></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">以如下</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">3 bytes Signed LEB128</span></span></span><span style="font-size: x-small;">數值為例</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0xd1 db 7e</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="22"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="23"></col><col width="24"></col><col width="24"></col></colgroup><tbody>
<tr class="alt"><td colspan="24" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="TOP" width="793"><span style="font-family: "Times New Roman", serif;">Bitwise diagram of a three-byte LEB128 value</span></td></tr>
<tr valign="TOP"><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="257"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">First Byte</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="258"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Second Byte</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="259"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Third Byte</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="22"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit6</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit5</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit4</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit3</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit13</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit12</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit11</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit10</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit9</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit8</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit7</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit20</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit19</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit18</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit17</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit16</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit15</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Bit14</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0xd1 & 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">2</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0xdb & 0x80 </span></span></span><span style="font-size: x-small;">不為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示尚未到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">3</span></span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">byte 0x7e & 0x80 </span></span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">0,</span></span></span><span style="font-size: x-small;">表示到結尾</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">所以</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Signed LEB128</span></span></span><span style="font-size: x-small;">結果為 </span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">((0xd1&0x7f + (0xdb&0x7f) <<7 + (0x7e&0x7f) <<14) << 11) >> 11= (0x1add1 << 11)>>11 = 0xffffadd1</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">LEB128</span></span></span><span style="font-size: x-small;">的形態還包括了</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Unsigned LEB128p1,</span></span></span><span style="font-size: x-small;">編碼的方式為將要編碼的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">32-bits</span></span></span><span style="font-size: x-small;">值加一後</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">,</span></span></span><span style="font-size: x-small;">依循</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Unsigned LED128</span></span></span><span style="font-size: x-small;">方式編碼為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1-5 bytes</span></span></span><span style="font-size: x-small;">的結果</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">,</span></span></span><span style="font-size: x-small;">解碼時</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">,</span></span></span><span style="font-size: x-small;">則將</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">1-5bytes Unsigned LEB128</span></span></span><span style="font-size: x-small;">的值</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">,</span></span></span><span style="font-size: x-small;">解回</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">32bits</span></span></span><span style="font-size: x-small;">值後減一</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">,</span></span></span><span style="font-size: x-small;">則可還原原本</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">32-bits</span></span></span><span style="font-size: x-small;">值的結果</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">.</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;"></span></span></span><span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Android</span></span></span><span style="font-size: x-small;">文件有如下表格</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">,</span></span></span><span style="font-size: x-small;">可以清楚表達 </span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Singed LEB128,Unsigned LEB128</span></span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: x-small;">Unsigned LEB128p1 </span></span></span><span style="font-size: x-small;">的差別</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: sans-serif, Arial;"></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 805px;"><colgroup><col width="190"></col><col width="191"></col><col width="191"></col><col width="192"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
編碼後的結果</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">Signed LEB128</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">Unsigned LEB128</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="192"><span style="font-family: "Times New Roman", serif;">Unsigned LEB128p1</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "Times New Roman", serif;">0x00</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="192"><span style="font-family: "Times New Roman", serif;">-1</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "Times New Roman", serif;">0x01</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="192"><span style="font-family: "Times New Roman", serif;">0</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "Times New Roman", serif;">0x7f</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">(0xffffffff) = -1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">127</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="192"><span style="font-family: "Times New Roman", serif;">126</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "Times New Roman", serif;">0x80 7f</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">(0xffffff80)= -128</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="191"><span style="font-family: "Times New Roman", serif;">16256</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="192"><span style="font-family: "Times New Roman", serif;">16255</span></td></tr>
</tbody></table>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其他變數型態列表如下</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 715px;"><colgroup><col width="190"></col><col width="503"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
型態名稱</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><div lang="zh-TW" style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說明</div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: "Times New Roman", serif;">byte</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">8-bit signed int</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">ubyte</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">8-bit unsigned int</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">short</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">16-bit signed int, little-endian</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">ushort</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">16-bit unsigned int, little-endian</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">int</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">32-bit signed int, little-endian</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">uint</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">32-bit unsigned int, little-endian</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">long</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">64-bit signed int, little-endian</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">ulong</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">64-bit unsigned int, little-endian</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">sleb128</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">signed LEB128</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">uleb128</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: sans-serif, Arial;">unsigned LEB128, variable-length (see below)</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="190"><span style="font-family: monospace;">uleb128p1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="503"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;">unsigned LEB128 plus </span><code style="font-family: "Courier New", Courier, monospace; font-size: 1em;"><span style="font-family: sans-serif, Arial;">1</span></code><span style="font-family: sans-serif, Arial;">, variable-length (see below)</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>MUTF-8 (Modified UTF-8) Encoding</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一個標準的<span style="font-family: "Times New Roman", serif;">UTF-8</span>編碼的格式如下所示 (也可以參考網頁 <span style="font-family: "Times New Roman", serif;">)<span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/UTF-8" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/UTF-8</a></span></span></span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 809px;"><colgroup><col width="89"></col><col width="90"></col><col width="90"></col><col width="90"></col><col width="90"></col><col width="90"></col><col width="90"></col><col width="95"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">Bits</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">Last code point</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">Byte 1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">Byte 2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">Byte 3</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">Byte 4</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">Byte 5</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">Byte 6</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">7</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">U+007F</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">0xxxxxxx</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">11</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">U+07FF</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">110xxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">16</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">U+FFFF</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">1110xxxx</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">21</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">U+1FFFFF</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">11110xxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">26</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">U+3FFFFFF</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">111110xx</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;">31</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">U+7FFFFFFF</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">1111110x</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><span style="font-family: "Times New Roman", serif;"><span style="font-family: sans-serif, Arial;"><span style="font-size: xx-small;">10xxxxxx</span></span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Dex</span>所遵循的語言編碼機制為<span style="font-family: "Times New Roman", serif;">MUTF-8,</span>跟<span style="font-family: "Times New Roman", serif;">UTF-8</span>的差異在於</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,</span>只有<span style="font-family: "Times New Roman", serif;">1,2,3 bytes</span>三種編碼長度<span style="font-family: "Times New Roman", serif;">,</span>也就是說<span style="font-family: "Times New Roman", serif;">MUTF-8</span>是專為<span style="font-family: "Times New Roman", serif;">UTF-16</span>編碼設計的<span style="font-family: "Times New Roman", serif;">,</span>最長支援<span style="font-family: "Times New Roman", serif;">16bits Unicode,</span>也因此<span style="font-family: "Times New Roman", serif;">,</span>不像<span style="font-family: "Times New Roman", serif;">UTF-8 </span>可支援<span style="font-family: "Times New Roman", serif;">4,5,6 bytes</span>長度編碼<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,</span>空字元<span style="font-family: "Times New Roman", serif;">(NULL)</span>不以<span style="font-family: "Times New Roman", serif;">0x00</span>編碼<span style="font-family: "Times New Roman", serif;">,</span>而是兩個<span style="font-family: "Times New Roman", serif;">bytes 0xc0 0x80,</span>可確保在編碼的字串中<span style="font-family: "Times New Roman", serif;">,</span>不會有<span style="font-family: "Times New Roman", serif;">0x00</span>出現<span style="font-family: "Times New Roman", serif;">,</span>也可避免在例如<span style="font-family: "Times New Roman", serif;">C</span>語言的處理時<span style="font-family: "Times New Roman", serif;">,</span>造成字串被截斷<span style="font-family: "Times New Roman", serif;">.(C</span>語言以<span style="font-family: "Times New Roman", serif;">0x00</span>做為字串的結尾<span style="font-family: "Times New Roman", serif;">).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3,</span>由於<span style="font-family: "Times New Roman", serif;">Java</span>中的字串都是以<span style="font-family: "Times New Roman", serif;">UTF-16</span>為單位<span style="font-family: "Times New Roman", serif;">(JNI C Code</span>中為<span style="font-family: "Times New Roman", serif;">UTF-8),</span>也因此在大於<span style="font-family: "Times New Roman", serif;">16bits Unicode</span>以上的編碼<span style="font-family: "Times New Roman", serif;">(</span>例如<span style="font-family: "Times New Roman", serif;">:U+10000 – U+10ffff ),</span>就會需要兩個<span style="font-family: "Times New Roman", serif;">Java</span>字元<span style="font-family: "Times New Roman", serif;">(16bits)</span>來表示<span style="font-family: "Times New Roman", serif;">,</span>反應到<span style="font-family: "Times New Roman", serif;">MUTF-8</span>中<span style="font-family: "Times New Roman", serif;">,</span>就會變成兩個<span style="font-family: "Times New Roman", serif;">3bytes</span>的編碼<span style="font-family: "Times New Roman", serif;">. (</span>對應到<span style="font-family: "Times New Roman", serif;">UTF-8</span>中為<span style="font-family: "Times New Roman", serif;">4bytes).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">Android</span></span>文件中也提到<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">,MUTF-8</span></span>類似於<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">CESU-8(</span></span>都是針對<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">UTF-16</span></span>設計的編碼<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">),</span></span>並支援<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">surrogate pairs,</span></span>相關資訊可以參考<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">CESU-8 Wiki (</span></span><span style="color: navy;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/CESU-8" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-family: Arial, sans-serif;">http://en.wikipedia.org/wiki/CESU-8</span></a></span></span><span style="font-family: Arial, sans-serif;"> ).</span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>結語</strong></span></div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div lang="zh-TW" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span>本文主要只涉及筆者認為值得說明的<span style="font-family: "Times New Roman", serif;">DEX</span>檔案格式內容<span style="font-family: "Times New Roman", serif;">,</span>然<span style="font-family: "Times New Roman", serif;">Android</span>還在持續的進版中<span style="font-family: "Times New Roman", serif;">,</span>對應到實作的正確性<span style="font-family: "Times New Roman", serif;">,</span>還請以各位手中的<span style="font-family: "Times New Roman", serif;">Source Code</span>為主<span style="font-family: "Times New Roman", serif;">. </span>感謝<span style="font-family: "Times New Roman", serif;">!</span></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-18859442820014136642017-06-01T09:53:00.001-07:002017-06-01T09:53:15.665-07:00Android筆記 – Dalvik的漫談<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android筆記 – Dalvik的漫談</h1>
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android</strong><strong>筆記 – Dalvik</strong><strong>的漫談</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
hlchou@mail2000.com.tw<br />by loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於Dalvik所涉及的範圍不少,從JNI介面,Trace-JIT的實作,到最佳化的技巧,筆者在本文只會針對自己挑選的區塊以Android 2.2 Source Code加以說明.同樣的,所有涉及的內容,都會隨著Android程式碼的改版而有所差異,還請以最新取得的Package為主.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在此引用侯捷曾說過的 “源碼之前了無秘密”,對有志於深入探究Dalvik運作原理的人而言,Android所釋出的Source Code,就是最好的Handbook.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Google的文件,我們知道Dalvik是Google在Android手機上所提供的ByteCode虛擬器,所預定的目標是要能運作在效能需求不高,較少的記憶體,與使用慢速的內部Flash儲存,作業系統要能支援虛擬記憶體,執行行程與執行緒(Process/Thread),與具備使用者帳號安全管理機制(UID-based security mechanisms),並能透過GNU C編譯器編譯後運作在包括Linux,BSD與Mac OS X等Unix環境下,並支援Little-endian與Big-endian處理器執行環境. 核心的函式庫主要是承襲Open Source的Java SE實作Apache Harmony而來(網址:<a href="http://harmony.apache.org/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://harmony.apache.org/</a> ),並基於Open Source中相關OpenSSL, zlib與ICU(International Components for Unicode) 的計畫成果.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般虛擬器的設計,會在應用程式啟動時,動態的從儲存裝置讀取並解壓縮個別的Classes到記憶體中,在沒有經過適度優化的架構下,每個獨立的虛擬器行程,都會包含自己一份的相關Classes記憶體空間,對於程式載入的固定成本與執行效率上,不容易有較好的表現.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因此,參考Google文件,Dalvik設計之初,基於上述的特徵與限制,主要著重在以下的目標,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,Class Data尤其是共用的ByteCode,要能跨行程共用,節省系統整體記憶體需求(參考Process Memory Map (in /proc/xxxx/maps),目前包括相關的 jar與所包含的Bytecode Dex檔案,都能跨行程在不同的Dalvik行程中共用).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,減少Dalvik應用程式載入啟動的成本,加速應用程式的反應時間</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,Class Data儲存在個別的檔案中,導致額外的儲存成本,針對儲存空間的需求需要多加注意.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,要從Class Data中讀取出資料數值( 例如:整數或是字串)會增加不必要的成本,評估如何採用C 的形式存取,會是有必要的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,ByteCode的驗證雖耗時但卻是必要的,應該試著在程式執行前完成驗證.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,透過快速指令集與機制的優化進行ByteCode的最佳化對於執行效率與電池壽命是相當重要的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,為了安全需求,執行中的行程不能修改共享的程式碼.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於上述目標,Dalvik在設計時,作了以下的決定</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,可以把多個Classes檔案整合到一個 DEX檔案中</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,DEX檔案會以唯讀方案載入到記憶體中,並跨行程共享</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,因應支援的系統架構,調整Byte Ordering與Word Alignment.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,ByteCode驗證對所有的Classes都是必要的,且會儘可能進行事先的驗證加速系統效率.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,對於需修改ByteCode的最佳化動作,會在執行前完成.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在dalvik上通常會以.apk的方式來提供應用程式的封裝,或以.jar的方式來提供Framework函式庫,這些包裝格式主要是以zip的形式壓縮內容並加上相關的參考資訊,儲存在檔案系統中,並達到節省儲存空間的目的.也因此,在執行前必須要進行解壓縮的動作,把DEX檔案載入到記憶體中執行. DEX檔案可包括多個Classes檔案,並以 classes.dex 檔名結尾.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>DEX</strong><strong>的驗證與最佳化</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
系統可以在VM進行JIT(Just in time),第一次安裝或在系統編譯時,進行最佳化DEX檔案的動作(ODEX – Optimized DEX),如果是在裝置上進行的最佳化動作,會把最佳化後的檔案存放到 dalvik-cache目錄下(例如:/data/dalvik-cache/system@framework@ext.<a href="mailto:jar@classes.dex" style="color: #666666; font-weight: bold; text-decoration-line: none;">jar@classes.dex</a>),若是在編譯階段的最佳化動作,則是把最佳化後的DEX檔案存放在jar/apk格式的ZIP壓縮檔案中,可成為產品出貨時預設System Image的一部分.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行時期的dalvik-cache目錄權限為0771並屬於system使用者與system群組(例如:drwxrwx–x system system),最佳化後的DEX檔案權限為0644並屬於system使用者與使用者群組(例如:-rw-r–r– system app_29),而有被DRM-locked保護的應用程式最佳化後的DEX檔案權限會設定為0640以避免其他應用程式取得檔案資料.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android SDK中的System.img 所包含的init.rc,在啟動過程中會進行如下的配置</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# create dalvik-cache and double-check the perms</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mkdir /data/dalvik-cache 0771 system system</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
chown system system /data/dalvik-cache</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
chmod 0771 /data/dalvik-cache</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最佳化DEX的動作會產生一個可供快速載入執行的classes.dex檔案,並會進行包括byte-swapping,structure realigning與basic structure checks,更新ODEX(Optimized DEX)header ,為了確保產生ODEX流程的正確性,Android提供了一個dexopt工具(原始碼在dalvik/dexopt),用來作為一個Dalvik虛擬器的輔助工具,可以在系統啟動時,透過Dalvik虛擬器對載入的DEX檔案執行最佳化的動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
工具dexopt在Android系統中有兩種使用的時機,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,由Dalvik虛擬器來執行,在有多個Dalvik虛擬器執行的環境中,會透過dexopt locks確保同一個DEX檔案只會執行到一次.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,在安裝應用程式時, 會把檔案從ZIP壓縮中解開,再透過dexopt進行驗證與最佳化<br />針對DEX檔案所進行的驗證與最佳化程序內容,如下簡介</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,驗證:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會包括DEX檔案中所包括的每個Classes集合以及每個指令集,確保不會在Run-Time階段遇到不適當的指令集,一般而言,Dalvik只有針對被驗證過的Classes進行依據平台的最佳化流程(這條件是可修改的,甚至也可忽略驗證階段只進行最佳化),如果呼叫了一個被驗證失敗的Class所提供的呼叫,就會導致Dalvik虛擬器發生Exception例外, DEX中的Class一旦被驗證過,就會被記錄在ODEX格式的欄位中(包含32-bit check-sum),如此可以避免下次載入時,還要重複進行驗證的工作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,最佳化:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會包括把數值資料的定義,透過指標對應到內部的資料結構,把一定成功或是特定行為的指令流程置換為比較簡單的形式,除了必須要在Run-Time才能取得的資訊外,會把可以先決定的資訊先靜態處理完畢.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
A, 以vtable Index置換虛擬函式(virtual method calls)Index</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
B, 變數的存取,會以實際資料的Byte Offset置換,並且會把資料型別為boolean / byte / char / short 等變數,轉為32bits的形式儲存</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
C,置換大量調用的函式,例如 String.length() 透過 Inline的置換,直接由Intepreter呼叫到原生函式的實作,減輕函式呼叫的成本,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
D,移除空函式的實作,例如Class物件的init空函式,在每次物件被配置時,都還是會被呼叫,就會以nop指令集(0x00)取代.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
E,將可以預先計算的資料,進行預處理.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
F,會以Dalvik規格中沒有制定的OpCode指令集來進行最佳化,這部份會交由dexopt根據Dalvik虛擬器的版本去決定哪些部分要置換.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
G.最佳化的流程,也可以看做是跟ELF執行檔與動態函式庫間解決Symbol Resolve的問題,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
上述的最佳化動作,也會使用到來自其他DEX檔案中的Class,如果所參考到的Class資料的內容或是函式有所變動,就會有相依性的問題要被處理,並且要針對變動的部份重新進行最佳化的動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>DEX </strong><strong>相依性</strong><strong>.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於,最佳化時,會把系統相依的問題進行解決,以加速應用程式載入的效率,也因此,這些在最佳化時所仰賴的相關DEX檔案如果有變動的話,就有機會導致原本最佳化的結果可能造成因為版本差異的所導致的系統問題,也因此,最佳化過的ODEX(Optimized DEX)檔案中會包括所相依的DEX檔案清單以及其CRC-32,時間資訊,對應到dalvik-cache的完整路徑,SHA-1簽名,Dalvik虛擬器版本編號. 基於此,如果啟動目錄下的DEX檔案變動,也就象徵著會導致系統上一次相依到該DEX檔案的驗證與最佳化流程,需要被重新執行. 如果使用者自定的Class命名與啟動路目錄下的Class名稱重複,系統會對該Class標註並且該參考將不會被驗證與最佳化流程解析. 如果DEX檔案在安裝時就是以ODEX的形式安裝,且他所相依的DEX檔案被更新過,這將會導致dexopt沒有辦法對該DEX檔案依據目前系統的狀況進行最佳化產生ODEX,此時Dalvik虛擬器將會拒絕該DEX檔案安裝.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Dalvik</strong><strong>雜談</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik虛擬器支援大約230多個指令集OpCode,其中也包含部分由Dexopt插入到ByteCode執行檔中但目前尚未在Android文件”Bytecode for the Dalvik VM” 說明的OpCode指令.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
主要的Dalvik虛擬器實作,都是基於C Code,並具有平台移植性,除了JIT(Byte-Code Compiler to ARM/x86 Code)與JNI(Java Native Interface) Call Bridge有牽涉到跟平台有關的組語優化實作,這會牽涉到包括如何把Byte-Code針對ARMv5,ARMv7,VFP與 NEON指令集進行動態的產生與優化,以及由Java端呼叫到Native函式時,要如何根據平台的差異去針對例如C語言的函式參數傳遞進行優化(例如:x86的函式參數傳遞,是由右往左推到Stack中,而ARM的函式參數傳遞,是由左到右依序放到R0,R1,R2,R3通用暫存器),與函式呼叫與傳回值(例如:x86會根據傳回值的Type決定要用EAX或加上EDX暫存器,或是ARM會決定要用到R0或加上R1暫存器). 若你所使用的平台,並不在Dalvik JNI Call Bridge支援中,Google文件中也建議可以參考 open-source FFI library (A Portable Foreign Function Interface Library,網址:<a href="http://sourceware.org/libffi/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://sourceware.org/libffi/</a> ),裡面有關於不同平台的可移植函式呼叫實作.對應到Dalvik中這部分的實作位於Source Code的dalvik/vm/arch/目錄下,裡面有關於Java透過JNI機制呼叫到Native Code的實作函式void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc, const u4* argv, const char* signature, void* func, JValue* pReturn) (例如:在x86目錄下實作是在Call386ABI.S 與Hints386ABI.c,arm目錄下實作是CallEABI.S,CallOldABI.S 與HintsEABI.c,或generic目錄下的實作Call.c 與 Hints.c),其中,也有包括關於SH處理器Call Bridge的實作,這是由Hitachi與 Renesas公司實作後,貢獻到Android計畫中.(ㄟ….那MIPS也應該要這樣子做吧…@_@)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
函式 dvmPlatformInvoke主要目的是會用來把我們在Java端呼叫JNI函式時所帶入的參數,用C函式參數傳遞的原則進行調整,與處理C函式的回傳值對應回Java的世界中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik支援兩種Java虛擬器的直譯器,一個是最早的版本,在文件中稱為Portabl Interpreter,所在原始碼路徑為dalvik/vm/mterp/portable,這個all-in-one-function的C實作,可以用來編譯到不同的平台上,並支援Profiling與除錯機制,根據Config的設定,所在編譯環境會納入編譯的Java虛擬器的直譯器實作會把Source Code放到dalvik/vm/mterp/out目錄下.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik也支援根據不同平台透過組語優化後的直譯器版本,在文件中稱為Fast Interpreter,可以藉由優化後的平台組語實作,得到更好的Java虛擬器執行效能,在dalvik/vm/mterp/out目錄下可以看到依據平台不同而命名的InterpC-<arch>.c, InterpAsm-<arch>.S原始碼,並可針對不同平台的差異採用不同的優化指令集,例如:在ARM11(ARMv6)架構下可以使用 PLD 指令,與在ARM7(ARMv4T)架構下要避免使用CLZ指令.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
組語版本的優化程式碼,會以64bytes Memory Alignment配置來實作每一個對應的Java指令(也就是說每個Java指令最多可以用16個ARM 32bits指令集實作),如果在Dalvik虛擬器啟動時,發現有對應實作的Java指令超過定義的大小,就會由虛擬器產生錯誤(Abort),參考InterpAsm-armv5te.S,如下指令集實作</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.balign 64</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.L_OP_MOVE_16: /* 0x03 */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* File: armv5te/OP_MOVE_16.S */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* for: move/16, move-object/16 */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* op vAAAA, vBBBB */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FETCH(r1, 2) @ r1<- BBBB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FETCH(r0, 1) @ r0<- AAAA</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FETCH_ADVANCE_INST(3) @ advance rPC, load rINST</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_VREG(r2, r1) @ r2<- fp[BBBB]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_INST_OPCODE(ip) @ extract opcode from rINST</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
SET_VREG(r2, r0) @ fp[AAAA]<- r2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GOTO_OPCODE(ip) @ jump to next instruction</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.balign 64</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.L_OP_MOVE_WIDE: /* 0x04 */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* File: armv5te/OP_MOVE_WIDE.S */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* move-wide vA, vB */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* NOTE: regs can overlap, e.g. “move v6,v7″ or “move v7,v6″ */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r2, rINST, lsr #8 @ r2<- A(+)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r3, rINST, lsr #12 @ r3<- B</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
and r2, r2, #1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
add r3, rFP, r3, lsl #2 @ r3<- &fp[B]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
add r2, rFP, r2, lsl #2 @ r2<- &fp[A]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ldmia r3, {r0-r1} @ r0/r1<- fp[B]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FETCH_ADVANCE_INST(1) @ advance rPC, load rINST</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_INST_OPCODE(ip) @ extract opcode from rINST</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
stmia r2, {r0-r1} @ fp[A]<- r0/r1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GOTO_OPCODE(ip) @ jump to next instruction</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也可以參考網頁<a href="http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html</a> ,有整理好的Dalvik Java OpCode, 對比Sun Java的OpCode (可以參考網頁:<a href="http://java.sun.com/docs/books/jvms/second_edition/html/Mnemonics.doc.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://java.sun.com/docs/books/jvms/second_edition/html/Mnemonics.doc.html</a> 或是比較完整的文件<a href="http://java.sun.com/docs/books/jvms/second_edition/Java5-Instructions2.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://java.sun.com/docs/books/jvms/second_edition/Java5-Instructions2.pdf</a> ),對比之後可以知道雖然都是透過JDK編譯的程式碼,透過Google Android Dex轉換後,就會變成Dalvik專屬的OpCode在Dalvik自己的Java虛擬器上執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
針對使用者所採用平台的組語優化程式碼,可以透過dalvik/vm/mterp/config-<Arch>相關檔案來決定,其中包括要import哪一部分的實作,也規避掉了ARM在不同架構上支援指令集的差異. 以dalvik/vm/mterp/config-armv4t為例,擷取其中關於opcode 的部分來說明如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# opcode list; argument to op-start is default directory</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op-start armv5te</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op OP_AGET_WIDE armv4t</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op OP_APUT_WIDE armv4t</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op OP_IGET_WIDE armv4t</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op OP_IGET_WIDE_QUICK armv4t</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op OP_IPUT_WIDE armv4t</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op OP_IPUT_WIDE_QUICK armv4t</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op OP_SGET_WIDE armv4t</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op OP_SPUT_WIDE armv4t</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
op-end</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
上述宣告,最後產生的dalvik/vm/mterp/out/InterpAsm-armv4t.S除上述AGET_WIDE,APUT_WIDE,IGET_WIDE,IGET_WIDE_QUICK,IPUT_WIDE,IPUT_WIDE_QUICK,SGET_WIDE與SPUT_WIDE指令集會用armv4t的實作外,其他指令集會用armv5te的指令集架構實現. 如果有修改上述指令集的實作,會需要執行dalvik/vm/mterp/rebuild.sh,重新產生dalvik/vm/mterp/out/ 下對應到相關處理器架構的Java指令集實作.並重新編譯dalvik目錄,以便產生對應這次修改的 libdvm.so .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Fast Interpreter會是預設的Dalvik虛擬器中的直譯器,如果你所在的處理器沒有Dalvik的組語實作支援,可以由使用者在啟動時選擇要用C Code版本的Portable Interpreter,只要在啟動時(例如在init.rc中)執行 “echo dalvik.vm.execution-mode = int:portable >> /data/local.prop “,就可以選擇採用Portable Interpreter.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般Java虛擬器直譯器的實作,最直覺的寫法就是用一個很大的Switch-Case,依序對應每個進來的指令集OpCode,做出對應OpCode的行為,在每個指令集OpCode執行完畢後,就回到迴圈的頭,重新Fetch下一次的指令,繼續Siwtch-Case的行為. Google文件中提到的另一種改善的技巧就是透過”threaded execution”,在每個指令集OpCode執行結束後,進行下一個指令集的fetch 與 dispatch,省去要回到迴圈啟始點(Branch)的固定成本.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik直譯器的實作,採用預先算好的Goto位址,基於每個直譯器處理的指令集OpCode實作,都固定以64bytes為Memory Alignment,取代得到一個指令集OpCode後,要進行查表的成本,只要取得OpCode後乘上64bytes(等於2的6次方,可以透過Shift的方式運算),就可以跳到對應指令集OpCode的實作.Android之所以選擇64bytes為每個指令集OpCode實作的最大空間,並沒有特別的理由,主要是這樣的值可以完全適用於目前Android對於ARM與x86上實作的結果.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Source Code dalvik/libdex/OpCode.h中的DEFINE_GOTO_TABLE的宣告如下,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define DEFINE_GOTO_TABLE(_name) \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static const void* _name[kNumDalvikInstructions] = { \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* 00..0f */ \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_NOP), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_MOVE), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_MOVE_FROM16), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_MOVE_16), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_MOVE_WIDE), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_MOVE_WIDE_FROM16), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_MOVE_WIDE_16), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_MOVE_OBJECT), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
H(OP_MOVE_OBJECT_FROM16), \</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
………………………..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…………………………………etc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再參考Source Code dalvik/vm/mterp/cstubs/entry.c,有如下宣告</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/*</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* Handler function table, one entry per opcode.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*/</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef H</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define H(_op) dvmMterp_##_op</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
DEFINE_GOTO_TABLE(gDvmMterpHandlers)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef H</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define H(_op) #_op</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
DEFINE_GOTO_TABLE(gDvmMterpHandlerNames)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
定義 gDvmMterpHandlers對應到每個OpCode的處理實作,與 gDvmMterpHandlerNames對應到每個OpCode的名稱.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再來追蹤函式bool dvmMterpStdRun(MterpGlue* glue) ,可以看到如下的Busy Loop</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
while (true) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
typedef void (*Handler)(MterpGlue* glue);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
u2 inst = /*glue->*/pc[0];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Handler handler = (Handler) gDvmMterpHandlers[inst & 0xff];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGVV(“handler %p %s\n”,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
handler, (const char*) gDvmMterpHandlerNames[inst & 0xff]);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*handler)(glue);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會每次取一個Java指令集OpCode,並透過 gDvmMterpHandlers 對應0x00-0xff範圍的Java指令集OpCode的對應處理函式. 在dalvik/vm/mterp/out/InterpAsm-<Arch>.S中,配合Fast Interpreter也有對應依據平台差異的函式dvmMterpStdRun 組語版本實作,跟C語言版本實作行為類似,但最大的差異在於,不是透過一個 while(true)的Busy Loop去逐一抓取給Dalvik虛擬器的指令集,而是先在函式dvmMterpStdRun中執行如下巨集 (以InterpAsm-armv5te.S實作為例)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FETCH_INST() @ load rINST from rPC</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_INST_OPCODE(ip) @ extract opcode from rINST</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GOTO_OPCODE(ip) @ jump to next instruction</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
抓取第一個Dalvik OpCode指令並執行,同時在每個指令執行結束後,再透過FETCH_ADVANCE_INST與GET_INST_OPCODE抓取下一個Dalvik OpCode指令,最後再透過GOTO_OPCODE執行該指令集的實作,如此持續運作下去,藉此得到比用C版本Busy Loop更高的執行效率.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果因為進行記憶體的Garbage Collection,進行除錯或是轉換到Native Code執行,而讓執行中的Dalvik行程處於Suspend狀態,Dalvik直譯器會提供一個安全機制,確保行程可以被正確的回復執行. 如下所示,目前Dalvik主要支援Portable/Fast Interpreter,而Trace-JIT主要是屬於Fast-Interpreter實作中的一部分.</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="148">Trace-JIT/Compiler<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(For Hot Fragments)</strong></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="144">Fast Interpreter<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(For Cold Fargments)</strong></div>
</td><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">Portable Interpreter<br />(C Code)</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="292">Fast Interpreter (ASM)</td></tr>
<tr class="alt"><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="467"><strong>Dalvik VM</strong></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik上每一個應用程式不管是SDK或是NDK都會基於一個Java Based的應用程式為主體(NDK為Java+ELF .so),也因此要了解Android的應用程式Framework,最適當的途徑就是把Dalvik的運作原理與基礎做一個分析,相對這會對於在Android架構下,不管是開發應用程式或是進行系統的效能優化都會有相當的助益.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Dalvik</strong><strong>的控制與範例</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果是透過PC上的系統參數設定操作,可以透過adb設定如下的指令</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#設定系統參數</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
adb shell setprop <name> <value></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#取得系統參數</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
adb shell getprop <name></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
相關的Dalvik系統參數設定,是在Zygote行程載入時進行初始化的,一旦相關的系統參數被更動到,就必須要重啟Dalvik Run-Time環境,透過Zygote載入流程讓相關系統參數發揮作用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在開發階段,有測試系統參數的需求時,就可以藉由Android的Shell,透過Stop/Start指令,終止與重啟Dalvik Run-Time環境,讓系統參數發揮作用.(Stop會依序設定系統參數 ctl.stop=runtime與ctl.stop=zygote,Start會依序設定系統參數ctl.start=zygote與ctl.start=runtime)</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">系統參數</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">值</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.stack-trace-file</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">/data/anr/traces.txt</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">Stack Dumps<br />範例: setprop dalvik.vm.stack-trace-file /tmp/stack-traces.txt<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik虛擬器在收到 Linux Signal SIGQUIT (也可透過kill -3觸發)就會把目標行程所有執行緒的Stack Traces內容(可以知道每個執行緒函式呼叫的Call Stack),根據這個參數指定的路徑把資料寫入,供開發者分析問題時參考之用.</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.dexopt-flags</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">m=y</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">Bytecode Verification and Optimization<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
範例:setprop dalvik.vm.dexopt-flags v=a,o=v</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
用來決定dexopt所進行執行前的驗證與最佳化動作的行為,在實際的裝置上,dexopt會在Dalvik啟動一個應用或是應用程式安裝時調用(會透過dexlock確保同時只有一個被執行到),</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
進一步說明參數如下</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
v=a,o=v =>驗證所有的Dex檔案,並且只最佳化被驗證過的Dex檔案,如果驗證失敗,該Dex檔案就不會被執行</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
v=n,o=v =>關閉驗證Dex的動作,只針對有被驗證過的Dex進行最佳化,沒被驗證過的Dex,就會直接執行(也不會被最佳化)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據Android的文件,第一次執行的Dex檔案,進行驗證的動作,可能會讓執行時間慢了40%左右,但只要該Dex檔案有驗證過,並且對應放在dalvik-cache下,只要該檔案沒有變動且所相依的其他Dex檔案也沒有更動過,之後執行就可省去驗證的流程,並可透過最佳化機制,加速應用程式的啟動執行.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Enabling type-precise GC results in larger optimized DEX files. The additional storage requirements for “.odex” files can cause /system to overflow on some devices, so this is configured separately for each product.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.lockprof.threshold</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">500</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">Enable Dalvik lock contention logging for userdebug builds.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.checkjni</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">true/false</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">Extended JNI Checks<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
範例:setprop dalvik.vm.checkjni true</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果系統沒有設置 dalvik.vm.checkjni,就會以 ro.kernel.android.checkjni為主,如果有設置 dalvik.vm.checkjni(不論是true或false),則以 dalvik.vm.checkjni為依據來決定CheckJNI的開或關</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
另一個對應的參數為 ro.kernel.android.checkjni,可在編譯時期透過build/core/main.mk決定.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這參數的設置,會讓JNI函式呼叫前,執行相關的稽核動作,其中包括</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,查核NULL Pointer</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,查核函式參數的正確性 (jclass is a class object, jfieldID points to field data, jstring is a java.lang.String)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,確認資料寫入動作與變數宣告一致. (例如: don’t store a HashMap in a String field.)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,確認是否有不允許的例外處理有因為函式呼叫正在等待例外的情況.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,確認關鍵的Get/Release呼叫沒有不適當的函式存在</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,確認JNIEnv不會被跨執行緒(Thread)分享</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,確認Local變數的參考不會超過該變數所能支援的變數壽命週期.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,UTF-8字串只會包含有效修改的UTF-8資料.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.jniopts</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">forcecopy</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">Extended JNI Checks<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
範例:setprop dalvik.vm.jniopts forcecopy</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.enableassertions</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">You can provide a class name, a package name (followed by “…”), or the special value “all”</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">Assertions<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
範例: setprop dalvik.vm.enableassertions all</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik虛擬器預設對於Assertion是關閉的,可以透過設定這個參數來開關Dalvik上Java程式碼Assertion的動作,</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.execution-mode</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">int:portable/int:fast/int:jit</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">Execution Mode<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
範例:</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
setprop dalvik.vm.execution-mode int:portable (C版本的Intepreter)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
setprop dalvik.vm.execution-mode int:fast (組語版本的Intepreter)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
setprop dalvik.vm.execution-mode int:jit (Just-in Time加速)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果有啟動Profiling或是接上Java除錯器,就會切到Debug Mode(我理解Debug Mode是在 C版本的Portable Intepreter中支援的),當除錯階段結束,或是Profiling結束,就會重新回復原本執行的Java模式.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果在AndroidManifest.xml中把android:vmSafeMode設定為true,就會預設關閉JIT選項,開發者可借此釐清應用程式所造成的問題,是否為JIT所導致的.</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.deadlock-predict err</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">off/warn/err</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">Deadlock Prediction<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
範例:setprop dalvik.vm.deadlock-predict err</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
編譯Dalvik時必須要加上 WITH_DEADLOCK_PREDICTION便能支援這個功能,參考Android文件,這機制主要用來進行Dalvik上Deadlock的預測,而非偵測</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果設定為off就是關閉,warn是記錄這個問題,但程式繼續執行,如果是err就是在Dalvik OpCpde OP_MONITOR_ENTER(0x1d)指令執行完畢後,立刻觸發Exception,終止Dalvik虛擬器的執行.</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.check-dex-sum</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">DEX File Checksums<br />範例:setprop dalvik.vm.check-dex-sum true<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前Dalvik虛擬器預設對載入ODEX(Optimized DEX)的流程,是不做Checksum確保的,參考dalvik-cache,跟系統與Framework有關的ODEX,所Owner與Group會是root或system,只有一般應用執行的ODEX,會把Group設定為對應的AP Group,基於此,Android預設透過系統存取權限的保護,就可以防止ODEX檔案被修改的可能.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果所在的儲存媒體不可靠,容易有資料損毀的問題發生,就會有必要加入Checksum的機制(其實以目前很多SmartPhone用 MLC NAND+FTL Controller的組合,只要Wear-Leveling有作用,要遇到儲存裝置的”不可靠”,對一般使用者而言,應該是很不容易遇到). 開發階段,也可以透過dexdump工具,手動的確認DEX檔案的Checksum.</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="152">dalvik.vm.jit.profile</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">true/false</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="372">JIT Profile<br />範例:setprop dalvik.vm.jit.profile true<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以用來查看Dalvik JIT對於熱門執行區塊的統計資訊.</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>有關</strong><strong>Dalvik</strong><strong>行程與執行時期介紹</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,為Android系統應用程式啟動的父子行程關係,我們可以看到init會把包括Service Manager,Netd,Rild,MediaServer,BootAnimation這些原生行程載入,而Dalvik的第一個初始化程式會透過app_process載入後,並命名為Zygote(ㄟ …Google翻譯查詢是 “受精卵”),再由Zygote帶起system_server與後續的Dalvik應用程式.</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="652">Kernel(PID=0)</td></tr>
<tr><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="80"></td><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="86">/init(PID=1)</td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="486">/system/bin/sh(PID=27)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/servicemanager(PID=28)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/vold(PID=29)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/netd(PID=30)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/debuggerd(PID=31)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/rild(PID=32)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/mediaserver(PID=34)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/dbus-daemon(PID=35)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/installd(PID=36)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/keystore(PID=37)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/sh(PID=38)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/qemud(PID=39)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/sbin/adbd(PID=41)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/bootanimation(PID=81)</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="149">zygote(PID=33)</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="337">system_server (pid:74)<br />com.android.inputmethod.latin (pid:146)<br />com.android.phone (pid:150)<br />android.process.acore (pid:189)<br />com.android.launcher (pid:191)<br />com.android.quicksearchbox (pid:229)<br />android.process.media (pid:259)<br />com.android.bluetooth (pid:273)<br />com.android.providers.calendar (pid:280)<br />com.android.email (pid:292)<br />com.android.mms (pid:305)<br />com.android.protips (pid:323)<br />com.android.music (pid:329)<br />com.cooliris.media (pid:335)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="86">kthreadd(PID=2)</td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="486">ksoftirqd/0(PID=3)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
events/0(PID=4)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
khelper(PID=5)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
suspend(PID=6)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kblockd/0(PID=7)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cqueue(PID=8)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kseriod(PID=9)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kmmcd(PID=10)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pdflush(PID=11)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pdflush(PID=12)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kswapd0(PID=13)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
aio/0(PID=14)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mtdblockd(PID=22)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kstriped(PID=23)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
hid_compat(PID=24)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
rpciod/0(PID=25)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mmcqd(PID=26)</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以目前筆者環境,列舉一個Dalvik應用程式CalendarProvider的記憶體Mapping資訊. 對應到其他Dalvik應用程式,我們可以看到基於Apriori prelink機制,在共用原生碼動態函式庫.so的部份,不同的Dalvik應用程式,也會對應到同樣的記憶體位置. 而在Dalvik OpCpde編碼動態函式庫有共用的.jar (會被解開為 classes.dex)部分,在跨不同的Dalvik應用程式,會被配置到同樣的記憶體位址.</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">記憶體位址</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">屬性</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">對應的執行檔或是函式庫名稱</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">00008000-00009000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/bin/app_process</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">00009000-0000a000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/bin/app_process</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">0000a000-001f9000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">[heap]</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">40000000-40008000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/system_properties</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">40008000-40009000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">40009000-4024a000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/mspace/dalvik-heap/zygote/0</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4024a000-41009000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/mspace/dalvik-heap/zygote/0</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">41009000-41038000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/fonts/DroidSans.ttf</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">41038000-4104c000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4104c000-4104d000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/dalvik-LinearAlloc</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4104d000-41254000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/dalvik-LinearAlloc</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">41254000-4154c000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/dalvik-LinearAlloc</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4154c000-4175b000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/framework/core.jar</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4175b000-41c23000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/data/dalvik-cache/system@framework@core.jar@classes.dex</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">41c23000-41c68000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">41c68000-41ca2000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/framework/ext.jar</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">41ca2000-41d2e000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/data/dalvik-cache/system@framework@ext.jar@classes.dex</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">41d2e000-41fc5000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/framework/framework.jar</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">41fc5000-425f2000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/data/dalvik-cache/system@framework@framework.jar@classes.dex</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">425f2000-42676000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">42676000-4268b000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/framework/android.policy.jar</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4268b000-426b9000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/data/dalvik-cache/system@framework@android.policy.jar@classes.dex</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">426b9000-42752000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/framework/services.jar</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">42752000-428a0000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/data/dalvik-cache/system@framework@services.jar@classes.dex</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">428a0000-428a3000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">428a3000-428d9000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/dalvik-heap-bitmap/objects</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">428d9000-428df000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">428df000-428e0000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/SurfaceFlinger read-only heap</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">428e0000-42907000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">42907000-4290c000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"><strong>/system/app/CalendarProvider.apk</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4291a000-4294b000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4294b000-42982000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/dalvik-heap-bitmap/mark/0</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">42982000-429c2000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/dalvik-heap-bitmap/mark/1</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170"><strong>429c2000-42a16000</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"><strong>/system/app/CalendarProvider.apk</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">42a16000-42a29000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/framework/android.test.runner.jar</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">42a29000-42a55000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/data/dalvik-cache/system@framework@android.test.runner.jar@classes.dex</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">42a70000-42e23000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/framework/framework-res.apk</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">42e23000-4304e000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/framework/framework-res.apk</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4304e000-4308f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/mspace/dalvik-heap/zygote/1</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">4308f000-43e0e000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/mspace/dalvik-heap/zygote/1</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">43e0e000-43e4f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/mspace/dalvik-heap/2</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">43e4f000-44b8e000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/ashmem/mspace/dalvik-heap/2</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44b8e000-44b8f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44b8f000-44c8e000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44c8e000-44c8f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44c8f000-44d8e000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44d8e000-44e8c000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/dev/binder</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44e8c000-44e8d000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44e8d000-44f8c000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44f8c000-44f8d000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">—p</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">44f8d000-4508c000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170"><strong>4508c000-450e0000</strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xs</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"><strong>/system/app/CalendarProvider.apk</strong></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">450e0000-451ab000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/data/dalvik-cache/system@app@CalendarProvider.apk@classes.dex</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">80000000-801d0000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libicudata.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">801d0000-801d1000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libicudata.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">80200000-80286000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libdvm.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">80286000-80289000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libdvm.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">80289000-8028a000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">9d100000-9d139000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstlport.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">9d139000-9d13b000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstlport.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">9d700000-9d736000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libjpeg.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">9d736000-9d737000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libjpeg.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">9ea00000-9ea08000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libdrm1.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">9ea08000-9ea09000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libdrm1.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a2f00000-a2fa9000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstagefright.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a2fa9000-a2fac000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstagefright.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a3500000-a3503000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstagefright_color_conversion.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a3503000-a3504000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstagefright_color_conversion.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a3600000-a3605000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstagefright_avc_common.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a3605000-a3606000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstagefright_avc_common.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a3700000-a370c000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstagefright_amrnb_common.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a370c000-a370d000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstagefright_amrnb_common.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a3900000-a39c7000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libopencore_common.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a39c7000-a39cd000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libopencore_common.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a4800000-a48b6000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libopencore_player.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a48b6000-a48be000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libopencore_player.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a5900000-a5917000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libomx_amrenc_sharedlibrary.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a5917000-a5918000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libomx_amrenc_sharedlibrary.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a6800000-a682f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libopencore_net_support.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a682f000-a6832000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libopencore_net_support.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a6d00000-a6d14000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libomx_sharedlibrary.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a6d14000-a6d15000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libomx_sharedlibrary.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a7500000-a7502000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libemoji.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a7502000-a7503000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libemoji.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a7e00000-a7e05000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libhardware_legacy.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a7e05000-a7e06000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libhardware_legacy.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a7f00000-a7f01000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libhardware.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a7f01000-a7f02000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libhardware.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8100000-a8124000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libutils.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8124000-a8125000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libutils.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8200000-a821f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libbinder.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a821f000-a8225000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libbinder.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8300000-a86ec000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libwebcore.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a86ec000-a8747000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libwebcore.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8747000-a8749000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8a00000-a8a14000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libexpat.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8a14000-a8a16000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libexpat.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8b00000-a8b4d000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libsqlite.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a8b4d000-a8b4f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libsqlite.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9000000-a9051000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libmedia.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9051000-a905d000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libmedia.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9300000-a930c000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libmedia_jni.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a930c000-a930d000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libmedia_jni.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9400000-a941c000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libvorbisidec.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a941c000-a941d000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libvorbisidec.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9500000-a9552000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libsonivox.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9552000-a9553000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libsonivox.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9553000-a9554000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9c00000-a9c0a000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libskiagl.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">a9c0a000-a9c0b000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libskiagl.so</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ab100000-ab211000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libskia.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ab211000-ab215000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libskia.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ab215000-ab218000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ab900000-ab912000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libui.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ab912000-ab914000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libui.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">aba80000-aba90000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libcamera_client.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">aba90000-aba93000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libcamera_client.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">abb00000-abb09000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libexif.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">abb09000-abb0a000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libexif.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">abb0a000-abb0c000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">abd00000-abd02000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libETC1.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">abd02000-abd03000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libETC1.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">abe00000-abe08000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libEGL.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">abe08000-abe09000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libEGL.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">abe09000-abe0b000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ac100000-ac104000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libGLESv2.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ac104000-ac105000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libGLESv2.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ac200000-ac205000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libGLESv1_CM.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ac205000-ac206000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libGLESv1_CM.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ac700000-ac715000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libsurfaceflinger_client.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ac715000-ac718000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libsurfaceflinger_client.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ac900000-ac919000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libpixelflinger.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ac919000-ac91b000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libpixelflinger.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ad100000-ad12f000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libnativehelper.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ad12f000-ad132000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libnativehelper.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ad300000-ad36d000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libandroid_runtime.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ad36d000-ad375000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libandroid_runtime.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ad375000-ad37a000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ad900000-ad9e0000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libicui18n.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ad9e0000-ad9e4000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libicui18n.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ad9e4000-ad9e5000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ade00000-aded0000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libicuuc.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">aded0000-aded8000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libicuuc.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">aded8000-adeda000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ae300000-ae304000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libnetutils.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ae304000-ae305000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libnetutils.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ae400000-ae402000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libwpa_client.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">ae402000-ae403000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libwpa_client.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af000000-af08d000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libcrypto.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af08d000-af09f000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libcrypto.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af09f000-af0a1000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af400000-af424000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libssl.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af424000-af427000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libssl.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af700000-af713000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libz.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af713000-af714000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libz.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af900000-af90e000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libcutils.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af90e000-af90f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libcutils.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">af90f000-af91e000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afa00000-afa03000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/liblog.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afa03000-afa04000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/liblog.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afb00000-afb20000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libm.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afb20000-afb21000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libm.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afc00000-afc01000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstdc++.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afc01000-afc02000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libstdc++.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afd00000-afd3f000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libc.so</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afd3f000-afd42000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/lib/libc.so</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">afd42000-afd4d000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">b0001000-b000c000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">r-xp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/bin/linker</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">b000c000-b000d000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">/system/bin/linker</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">b000d000-b0016000</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">bea87000-bea9c000</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73">rwxp</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">[stack]</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170">0xc0000000———</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423">LINUX KERNEL</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="170"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="73"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="423"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>使用</strong><strong> </strong><strong>ANT </strong><strong>包裝</strong><strong>NDK</strong><strong>應用程式為</strong><strong>APK</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Java的應用,通常可以透過Ant來包裝動態函式庫.so檔案與Java應用程式為.apk,Ant是一個Apache計畫的產物,官方網站為<a href="http://ant.apache.org/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://ant.apache.org/</a> ,下載JUnit <a href="https://github.com/KentBeck/junit/downloads" style="color: #666666; font-weight: bold; text-decoration-line: none;">https://github.com/KentBeck/junit/downloads</a> ( 筆者下載的路徑是http://cloud.github.com/downloads/KentBeck/junit/junit-4.9b2.jar),把 junit-4.9b2.jar複製到 ant解開後的路徑 lib/optional下,然後如下設定環境變數</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(<a href="http://ant.apache.org/manual/index.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://ant.apache.org/manual/index.html</a>)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>export ANT_HOME=/usr/local/ant</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>export JAVA_HOME=/android/jdk1.5.0_22 </strong>(如果是Cygwin就設定到JDK安裝的路徑,例如 export JAVA_HOME=/cygdrive/c/”Program Files”/Java/jdk1.6.0_23)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>export PATH=${PATH}:${ANT_HOME}/bin</strong><br />與<br /><strong>NDK=/android-ndk-r5b-windows</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,執行 ./build.sh</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就可以產生ANT執行的環境,以NDK為例,可以進到範例目錄</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過 Android SDK tools下的 android.bat產生讓ANT參考的build.xml</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
snna@snna-PC /android-ndk-r5b-windows/samples/hello-jni</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$ <strong><span style="text-decoration-line: underline;">android.bat update project -p . -s</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Updated local.properties</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Added file C:\cygwin\android-ndk-r5b-windows\samples\hello-jni\build.xml</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Added file C:\cygwin\android-ndk-r5b-windows\samples\hello-jni\proguard.cfg</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Updated local.properties</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Added file C:\cygwin\android-ndk-r5b-windows\samples\hello-jni\tests\build.xml</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Added file C:\cygwin\android-ndk-r5b-windows\samples\hello-jni\tests\proguard.cfg</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過 ndk-build進行編譯</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
snna@snna-PC /android-ndk-r5b-windows/samples/hello-jni</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$ <strong>$NDK/ndk-build</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>(</strong><strong>要編譯 Debug </strong><strong>版本就是加上 NDK_LOG=1 NDK_DEBUG=1)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Gdbsetup : libs/armeabi/gdb.setup</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Install : libhello-jni.so => libs/armeabi/libhello-jni.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過ANT產生 APK</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
snna@snna-PC /android-ndk-r5b-windows/samples/hello-jni</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$ <strong>ant debug</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Buildfile: C:\cygwin\android-ndk-r5b-windows\samples\hello-jni\build.xml</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[setup] Android SDK Tools Revision 8</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[setup] Project Target: Android 2.2</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……………………..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
debug:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[echo] Running zip align on final apk…</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[echo] Debug Package: C:\cygwin\android-ndk-r5b-windows\samples\hello-jni\bin\HelloJni-debug.apk</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BUILD SUCCESSFUL</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Total time: 5 seconds</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
安裝 APK 到android手機環境</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
snna@snna-PC /android-ndk-r5b-windows/samples/hello-jni</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$<strong> adb install bin/HelloJni-debug.apk (</strong><strong>如果之前有安裝過,</strong><strong>可以加上 -r,</strong><strong>重新安裝)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
396 KB/s (79155 bytes in 0.195s)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pkg: /data/local/tmp/HelloJni-debug.apk</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Success</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
安裝完畢後,如果希望透過ndk-gdb除錯時,可以在程式啟動後,立刻停住等待除錯器啟動,不要就直接執行下去,可以修改Java程式碼加入函式呼叫 android.os.Debug.waitForDebugger() , 如下所示,修改 /android-ndk-r5b-windows/samples/hello-jni/src/com/example/hellojni/HelloJni.java</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
package com.example.hellojni;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.app.Activity;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.widget.TextView;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.os.Bundle;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public class HelloJni extends Activity</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/** Called when the activity is first created. */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@Override</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public void onCreate(Bundle savedInstanceState)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
android.os.Debug.waitForDebugger();</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
super.onCreate(savedInstanceState);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
snna@snna-PC /android-ndk-r5b-windows/samples/hello-jni</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$ <strong>$NDK/ndk-gdb –start</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GNU gdb 6.6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Copyright (C) 2006 Free Software Foundation, Inc.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GDB is free software, covered by the GNU General Public License, and you are</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
welcome to change it and/or distribute copies of it under certain conditions.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Type “show copying” to see the conditions.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
There is absolutely no warranty for GDB. Type “show warranty” for details.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
This GDB was configured as “–host=i586-mingw32msvc –target=arm-elf-linux”.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(no debugging symbols found)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Android Runtime</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
包括工具 dexopt,或是app_process(zygote)與dalvikvm這些在Android目錄下可以使用的執行檔,其實最主要的實作都是基於 /system/lib/libdvm.so,並且透過JNI串起原生程式碼與Java程式碼的介面,這些工具主要是把要傳遞給 libdvm.so處理的資料,進行前段的處理,如下以app_process為例說明Zygote程序的初始化流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik 第一個Java應用程式 Zygote,就由此而來, app_process Source Code所在路徑為frameworks/base/cmds/app_process.系統在初始化Zygote時,會帶入如下的參數</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/system/bin/app_process -Xzygote /system/bin –zygote –start-system-server</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於最終實作的內容是在Java Framework中的,com.android.internal.os.ZygoteInit (原始碼路徑:frameworks/base/core/java/com/android/internal/os/ZygoteInit.java),在app_process的C實作中,主要是初始化Dalvik虛擬器,並且把要帶入Java的資訊加以處理,我們簡要說明如下.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,在C程式碼中產生 AndroidRuntime (AndroidRuntime實作在frameworks/base/core/jni/AndroidRuntime.cpp)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,呼叫AndroidRuntime::addVmArguments把C參數的個數與內容扣掉屬於app_process的部份(個數減一與字串往前移動一).傳給AndroidRuntime</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,如果參數等於 –zygote 與隨後參數等於 –start-system-server 就把變數startSystemServer設為true,並呼叫set_process_name設定行程名稱為 zygote,再來執行AndroidRuntime::start(const char* className, const bool startSystemServer)函式,該函式會初始化Dalvik虛擬器(由AndroidRuntime::startVm呼叫函式JNI_CreateJavaVM(原始碼在:dalvik/vm/Jni.c)),並由C透過JNI介面(FindClass,GetStaticMethodID and CallStaticVoidMethod)執行Java的 com.android.internal.os.ZygoteInit Class(原始碼路徑:frameworks/base/core/java/com/android/internal/os/ZygoteInit.java)的 ZygoteInit::main函式,執行如下行為 (只列舉筆者覺得重要的)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3.a,註冊ZygoteSocket</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3.b,Preload所需的DEX/Class檔案,例如:會透過dvmJarFileOpen(原始碼在:dalvik/vm/JarFile.c),解開ZIP壓縮的JAR檔案,先確認是否有odex結尾的檔案(表示已經做過最佳化的動作),如果有,就會確認該odex檔案的Class相依性(如果有相依的Class被更新,就要重新進行最佳化),接下來搜尋是否有classes.dex結尾的檔案(尚未被最佳化過),並呼叫dvmOptimizeDexFile(原始碼在:dalvik/vm/analysis/DexOptimize.c)進行驗證與最佳化DEX的流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3.c,進行初始化後的記憶體回收動作 (GC,Memory Garbage Collection)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3.d,如果startSystemServer為true,呼叫startSystemServer產生System Server行程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3.e,Zygote進入一個Socket 等待Client連結的無窮迴圈. 至此即完成zygote行程的初始化動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,如果參數不為 –zygote, 就會把Class名稱與C參數的個數與內容扣掉屬於app_process的部份(個數減一與字串往前移動一).傳給AndroidRuntime. 並呼叫set_process_name設定行程為該Class名稱,再來執行AndroidRuntime::start(const char* className, const bool startSystemServer)函式,該函式會初始化Dalvik虛擬器,並由C透過JNI介面執行Java的 com.android.internal.os.RuntimeInit Class(原始碼路徑:frameworks/base/core/java/com/android/internal/os/RuntimeInit.java)的 RuntimeInit::main函式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>JNI (Java Native Interface)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
JNI的介面是原本Java環境中就有的機制,讓Java的應用程式可以跟其他語言實作的動態函式庫進行互通,更進一步來說,就是可以透過Native Code執行的高效率,優化Java應用程式執行上表現.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有兩份關於JNI的文件,是Google推薦開發者可以參考的</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,Introduction and Tutorial<br />(http://java.sun.com/docs/books/jni/html/jniTOC.html)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, Java Native Interface Specification for J2SE 1.6<br />(http://download.oracle.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
JNI的C函式可以存取 “JavaVM” 或”JNIEnv” 的資料結構,一個JNI C函式的第一個函式參數會是JNIEnv (例如:HelloWorld(JNIEnv * env, jobject jobj)),並且以Dalvik的設計而言,是以一個Java AP對應到一個Linux Process並對應到一個Dalvik VM的實體,也就是說,Dalvik VM本身並不會進行MultiTask Java AP的動作,同時,每個Java AP與其對應的JNI C 動態函式庫,就會以一個Linux Process行程空間(每個都是一個獨立的4GB記憶體空間)為單位來運作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
JNI可以透過FindClass取得Java世界所宣告的Class,透過GetFieldID取得Java世界的變數(並且也可以改變,設定值與使用該變數),與可以透過GetMethodID取得Java世界的Class函式呼叫.有關字元部分需要注意的是,Java世界採用的字元是以Unicode(UTF-16 LE)編碼,而在JNI的C世界中是採用UTF-8的方式編碼.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以c為例,在實作JNI的函式時,所面對的資料型態,主要是以j 開頭加上對應的Java端的資料型態,例如</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">Java中的型態</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">JNI 中的型態</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">對應到C實作中的型態</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">boolean</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jboolean</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">unsigned char ( unsigned 8 bits)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">byte</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jbyte</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">signed char (signed 8 bits)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">char</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jchar</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">unsigned short (unsigned 16 bits)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">short</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jshort</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">short (signed 16 bits)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">int</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jint</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">int (signed 32 bits)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">long</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jlong</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">long long (signed 64 bits)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">float</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jfloat</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">float (32-bit IEEE 754)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">double</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jdouble</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">double ( 64-bit IEEE 754)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">size</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jsize</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">int (signed 32 bits)</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">void</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">void</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">void</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">String</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jstring</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">void *</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">object</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jobject</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">void *</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">class</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jclass</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">void *</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">array</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jarray</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">void *</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="132">jobjectArray/jbooleanArray/jbyteArray/jcharArray/jshortArray/jintArray/jlongArray/jfloatArray/jdoubleArray/jthrowable/jweak</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="383">void *</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
需要注意的是,在Java中字元是以Unicode的方式編碼,所以jchar對應一個Java字元,才會等於一個unsigned short 16bits字元,但是在JNI這邊C語言的實作則是以UTF-8的方式來實現,也就是說ASCII字元固定為1個bytes,但中文或其他語系的編碼就會有2-6bytes不等的編碼長度(可以參考<a href="http://en.wikipedia.org/wiki/UTF-8" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/UTF-8</a> ),中文等亞洲語系通常為3bytes.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下,提供一個簡單沒有傳入參數與傳回值的JNI範例 libtest8.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <jni.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdio.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <string.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define LOG_TAG “C LOG DEMO”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef LOG</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <utils/Log.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
JNIEXPORT void JNICALL Java_loda_Test8_Test8_HelloWorld(JNIEnv * env, jobject jobj)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“Hello World in Console.\n”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGV(“Hello World! This color is for Verbose.”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGD(“Hello World! This color is for Debug.”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Hello World! This color is for Information”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGW(“Hello World! This color is for Warnning.”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGE(“Hello World! This color is for Error.”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過如下內容的Android.mk</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOCAL_PATH := $(my-dir)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
include $(CLEAR_VARS)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOCAL_SRC_FILES := libtest8.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOCAL_SHARED_LIBRARIES := liblog</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOCAL_MODULE := libtest8</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOCAL_PRELINK_MODULE := false</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
include $(BUILD_SHARED_LIBRARY)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
之後執行</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@localhost froyo]# make libtest8</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
============================================</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PLATFORM_VERSION_CODENAME=REL</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PLATFORM_VERSION=2.2.1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
TARGET_PRODUCT=generic</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
TARGET_BUILD_VARIANT=eng</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
TARGET_SIMULATOR=</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
TARGET_BUILD_TYPE=release</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
TARGET_BUILD_APPS=</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
TARGET_ARCH=arm</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
HOST_ARCH=x86</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
HOST_OS=linux</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
HOST_BUILD_TYPE=release</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
BUILD_ID=MASTER</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
============================================</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target thumb C: libtest8 <= system/core/libtest8/libtest8.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target SharedLib: libtest8 (out/target/product/generic/obj/SHARED_LIBRARIES/libt</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
est8_intermediates/LINKED/libtest8.so)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target Non-prelinked: libtest8 (out/target/product/generic/symbols/system/lib/li</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
btest8.so)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
target Strip: libtest8 (out/target/product/generic/obj/lib/libtest8.so)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Install: out/target/product/generic/system/lib/libtest8.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
之後,筆者把libtest.so放到Windows環境下,首先原本的system.img载入是唯讀的,必須要透過</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
adb reomunt</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
讓system.img可以寫入資料 (/dev/block/mtdblock0 /system yaffs2 rw 0 0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
之後,透過 adb push libtest8.so /system/lib</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
616 KB/s (25248 bytes in 0.040s)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
把函式庫放到目標主機上,然後透過Eclipse執行下面的程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
package loda.Test8;<br />import android.app.Activity;<br />import android.util.Log;<br />import android.os.Bundle;<br />import java.io.IOException;<br />import java.io.InputStream;<br />import java.lang.IllegalStateException;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public class Test8 extends Activity {<br />private native void HelloWorld();<br />static {<br />System.loadLibrary(“test8″);<br />}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@Override<br />public void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />Log.i(“loda”, “libtest8 Before Call JNI HelloWorld”);<br />HelloWorld();<br />Log.i(“loda”, “libtest8 After Call JNI HelloWorld”);<br />setContentView(R.layout.main);<br />}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就可以看到在Eclipse的環境中,的logcat有來自Java程式透過JNI介面呼叫HelloWorld C函式庫的結果了.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,我們把這個JNI範例加上傳入參數與傳回值,如下範例C程式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <jni.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdio.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <string.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define LOG_TAG “C LOG DEMO”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef LOG</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <utils/Log.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char gTest8Buffer[]=”Unicode based Global Sring Reference from JNI-C”;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
JNIEXPORT jstring JNICALL Java_loda_Test8d_Test8d_HelloWorld(JNIEnv * env, jobject jobj,jint test_int,jstring test_string,jdouble test_double)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
const jbyte *jni_string;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jni_string=(*env)->GetStringUTFChars(env,test_string,0);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(jni_string==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“int:%d string:%s double:%f\n”,test_int,jni_string,test_double);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“int:%d string:%s double:%f\n”,test_int,jni_string,test_double);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*env)->ReleaseStringUTFChars(env,test_string,jni_string);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return (*env)->NewStringUTF(env, gTest8Buffer);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們額外加入, int,String與double型態的參數,由Java端傳入給JNI的C程式,編譯後,同樣的透過adb push libtest8d.so /system/lib</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
61 KB/s (5164 bytes in 0.082s)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
傳到Android Target上,然後再Eclipse上編譯如下的Java程式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
package loda.Test8d;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.app.Activity;<br />import android.util.Log;<br />import android.os.Bundle;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public class Test8d extends Activity {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
private native String HelloWorld(int a,String b,double c);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static {<br />System.loadLibrary(“test8d”);<br />}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@Override<br />public void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />Log.i(“loda”, “libtest8d Before Call JNI HelloWorld”);<br />String vStr=”It is a string from Java”;<br />String vRet= HelloWorld(5799232,vStr,123.456);<br />Log.i(“loda”, vRet);<br />Log.i(“loda”, “libtest8d After Call JNI HelloWorld”);<br />setContentView(R.layout.main);<br />}<br />}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就可以示範如何從Java端傳遞整數,字串與浮點數給JNI C程式,然後再從C程式中傳遞結果字串給Java應用程式.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,我們再舉另一個例子,示範如何從JNI C程式中,去呼叫Java端的應用函式,如此我們就可以達成C與Java端彼此可以呼叫的結果,並且可以驗證這些JNI的行為在Android架構下確實可以運作無誤.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(參考:<a href="http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html</a> )</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">Signature</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">Java Type</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">Z</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">boolean</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">B</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">byte</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">C</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">char</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">S</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">short</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">I</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">int</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">J</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">long</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">F</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">float</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">D</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">double</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">L</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">fully-qualified-class;</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">[ type</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">type[]</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="175">( arg-types ) ret-type</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="215">method type</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,我們在JNI C函式中透過 GetMethodID取得Java函式String CallFromJNI(int a,String b,double c) 的c函式與參數宣告 “(ILjava/lang/String;D)Ljava/lang/String;”,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <jni.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdio.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <string.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define LOG_TAG “C LOG DEMO”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef LOG</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <utils/Log.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char gTest8Buffer[]=”Unicode based Global Sring Reference from JNI-C”;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
JNIEXPORT jstring JNICALL Java_loda_Test8d_Test8d_HelloWorld(JNIEnv * env, jobject jobj,jint test_int,jstring test_string,jdouble test_double)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jclass vClass=(*env)->GetObjectClass(env,jobj);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jmethodID vMethodID=(*env)->GetMethodID(env,vClass,”CallFromJNI”,”(ILjava/lang/String;D)Ljava/lang/String;”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vMethodID==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to load Java Func CallFromJNI”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jstring vStr=(*env)->NewStringUTF(env, gTest8Buffer);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jstring vRetStr=(*env)->CallObjectMethod(env,jobj,vMethodID,123,vStr,4321.1234);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
const jbyte *jni_string=(*env)->GetStringUTFChars(env,vRetStr,0);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(jni_string==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Java Method Return String:%s”,jni_string);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*env)->ReleaseStringUTFChars(env,vRetStr,jni_string);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return vStr;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過如下命令傳到手機上</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
adb push libtest8d.so /system/lib</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
419 KB/s (5160 bytes in 0.012s)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
再透過如下的Java 程式碼,就可以完成從Java呼叫JNI C函式,到由JNI C函式呼叫回Java函式的兩者互通的函式呼叫機制,並可在Android環境中驗證無誤,如下範例程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
package loda.Test8d;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.app.Activity;<br />import android.util.Log;<br />import android.os.Bundle;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public class Test8d extends Activity {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
private native String HelloWorld(int a,String b,double c);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static {<br />System.loadLibrary(“test8d”);<br />}<br />private String CallFromJNI(int a,String b,double c)<br />{<br />Log.i(“loda”, “int:”+a+”_String:”+b+”_double:”+c);<br />return “From CallFromJNI in Java”;<br />}<br />@Override<br />public void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />Log.i(“loda”, “libtest8d Before Call JNI HelloWorld”);<br />String vStr=”It is a string from Java”;<br />String vRet= HelloWorld(5799232,vStr,123.456);<br />Log.i(“loda”, vRet);<br />Log.i(“loda”, “libtest8d After Call JNI HelloWorld”);<br />setContentView(R.layout.main);<br />}<br />}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最後,再示範如何透過JNI C函式,去取得Java的Class變數的機制,雖然一般模組化的設計,跨模塊的變數存取最好都是透過函式實作來達成,直接去存取變數並不是一個好的實作方式,但本文的目的主要是演示這些JNI操作的實例作為相關設計的參考之用,所以,還請僅供各位參考,實作上還是建議可以透過函式來使用跨模組的變數,而不是直接自行存取造成後續維護或是問題收斂上的困難.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為JNI C程式碼的範例,由C程式碼去參考Java程式碼中宣告的int,String與double變數</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <jni.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdio.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <string.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define LOG_TAG “C LOG DEMO”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef LOG</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <utils/Log.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char gTest8Buffer[]=”Sring from JNI-C”;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
JNIEXPORT jstring JNICALL Java_loda_Test8e_Test8e_HelloWorld(JNIEnv * env, jobject jobj)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jfieldID vFieldID;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jint jInt;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jstring jStr;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jdouble jDouble;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
const char *vpTemp;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jclass vClass=(*env)->GetObjectClass(env,jobj);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/////////////////////////////////////////////</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Get and Set Integer from Java</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vFieldID=(*env)->GetFieldID(env,vClass,”IntInJava”,”I”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vFieldID==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to load Java Integer Variable”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jInt=(*env)->GetIntField(env,jobj,vFieldID);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(jInt==0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to get jInt Object”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“jInt:%d”,jInt);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jInt=987654321;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*env)->SetIntField(env,jobj,vFieldID,jInt);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/////////////////////////////////////////////</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/////////////////////////////////////////////</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Get and Set String from Java</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vFieldID=(*env)->GetFieldID(env,vClass,”StringInJava”,”Ljava/lang/String;”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vFieldID==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to load Java String Variable”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jStr=(*env)->GetObjectField(env,jobj,vFieldID);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(jStr==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to get jStr Object”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vpTemp=(*env)->GetStringUTFChars(env,jStr,NULL);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vpTemp==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to get UTF8 String Variable”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“jStr:%s”,vpTemp);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*env)->ReleaseStringUTFChars(env,jStr,vpTemp);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jStr=(*env)->NewStringUTF(env,”JNI C Copy to Java String Variable”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(jStr==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to allocate UTF8 String Variable”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*env)->SetObjectField(env,jobj,vFieldID,jStr);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
////////////////////////////////////////////////</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/////////////////////////////////////////////</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//Get and Set Double from Java</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vFieldID=(*env)->GetFieldID(env,vClass,”DoubleInJava”,”D”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vFieldID==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to load Java Double Variable”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jDouble=(*env)->GetDoubleField(env,jobj,vFieldID);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(jDouble==0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to get jDouble Object”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“jDouble:%f”,jDouble);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jDouble=9876.5432;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*env)->SetDoubleField(env,jobj,vFieldID,jDouble);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/////////////////////////////////////////////</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jstring vStr=(*env)->NewStringUTF(env, gTest8Buffer);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return vStr;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過如下命令傳到手機上</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
adb push libtest8e.so /system/lib</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
334 KB/s (5136 bytes in 0.015s)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,為搭配上述JNI C程式碼參考到Java中變數,所配套的Java 程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
package loda.Test8e;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.app.Activity;<br />import android.util.Log;<br />import android.os.Bundle;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public class Test8e extends Activity {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
private native String HelloWorld();<br />private int IntInJava;<br />private String StringInJava;<br />private double DoubleInJava;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static {<br />System.loadLibrary(“test8e”);<br />}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@Override<br />public void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />IntInJava=99999;<br />StringInJava=”String from Java”;<br />DoubleInJava=7777.6666;<br />Log.i(“loda”, “libtest8e Before Call JNI HelloWorld”);<br />String vRet= HelloWorld();<br />Log.i(“loda:”, “IntInJava:” + IntInJava);<br />Log.i(“loda:”,”StringInJava:” + StringInJava);<br />Log.i(“loda:”,”DoubleInJava:” + DoubleInJava);<br />Log.i(“Return String:”, vRet);<br />Log.i(“loda”, “libtest8e After Call JNI HelloWorld”);<br />setContentView(R.layout.main);<br />}<br />}<br />接下來,讓我們示範由JNI C程式碼中,透過初始化要使用的Java Class與使用所包含的Method</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <jni.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdio.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <string.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define LOG_TAG “C LOG DEMO”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef LOG</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <utils/Log.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char gTest8Buffer[]=”Sring from JNI-C”;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
JNIEXPORT jstring JNICALL Java_loda_Test8f_Test8f_HelloWorld(JNIEnv * env, jobject jobj)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jmethodID vMethodID;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jobject vNewObj;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jclass vClass=(*env)->FindClass(env,”loda/Test8f/MyJavaClass”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vClass==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to FindClass MyJavaClass”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/////</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vMethodID=(*env)->GetMethodID(env,vClass,”<init>”,”()V”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vMethodID==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to Get init of MyJavaClass”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vNewObj=(*env)->NewObject(env,vClass, vMethodID, NULL);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/////</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vMethodID=(*env)->GetMethodID(env,vClass,”MyRun”,”(Ljava/lang/String;)Ljava/lang/String;”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vMethodID==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to Get MyRun of MyJavaClass”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Get MyJavaClass Method MyRun”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jstring vStr=(*env)->NewStringUTF(env, gTest8Buffer);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
jstring vRetStr=(*env)->CallObjectMethod(env,vNewObj,vMethodID,vStr);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
const jbyte *jni_string=(*env)->GetStringUTFChars(env,vRetStr,0);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(jni_string==NULL)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Falied to GetStringUTFChars”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return NULL;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Java Method Return String:%s”,jni_string);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*env)->ReleaseStringUTFChars(env,vRetStr,jni_string);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(*env)->DeleteLocalRef(env,vClass);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return vStr;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過如下命令傳到手機上</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
adb push libtest8f.so /system/lib</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
417 KB/s (5132 bytes in 0.012s)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,為搭配上述JNI C程式碼參考到Java中變數,所配套的Java 程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
package loda.Test8f;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.app.Activity;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.util.Log;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.os.Bundle;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public class Test8f extends Activity {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
private native String HelloWorld();</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
System.loadLibrary(“test8f”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@Override</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public void onCreate(Bundle savedInstanceState) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
super.onCreate(savedInstanceState);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
String vRet= HelloWorld();</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Log.i(“Return String:”, vRet);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
setContentView(R.layout.main);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
class MyJavaClass implements Runnable</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public void run()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
public String MyRun(String StringFromJNIC)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
try</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Log.i(“loda:”, “in MyJavaClass:” + StringFromJNIC);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
catch(Exception e)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
e.printStackTrace();</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Log.i(“loda:”,”End of MyRun”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return “From MyJavaClass/MyRun in Java”;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過C程式要啟動Dalvik虛擬器,會透過呼叫函式 JNI_CreateJavaVM (實作在dalvik/vm/Jni.c中),之後透過函式dvmStartup(實作在dalvik/vm/Init.c),再呼叫函式dvmPrepMainThread(實作在dalvik/vm/Thread.c)產生Dalvik虛擬器的Main Thread.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Google從2.2版Foryo開始釋出NDK r4的版本,支援JNI單步除錯的機制.除了可以直接透過JNI介面開發 Java與Native Code的整合應用外,Google當然也提供了NDK的Framework,讓有這需求的開發者可以有一定程度的規範.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,我們就針對JNI的介面進一步的追蹤系統運作的原理,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以 hello-jni範例提供的JNI C函式Java_com_example_hellojni_HelloJni_stringFromJNI為例,進入到 Java_com_example_hellojni_HelloJni_stringFromJNI函式後,此時的Call Stack為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(gdb) bt full</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#0 Java_com_example_hellojni_HelloJni_stringFromJNI (env=0xaa50,thiz=0x43e1d078)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
at C:/cygwin/android-ndk-r5b-windows/samples/hello-jni/jni/hello-jni.c:30</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
No locals.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#1 0x80213978 in ?? ()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
確認Registers LR與PC</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lr 0x80213978 2149661048</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pc 0x803002e4 0x803002e4 <Java_com_example_hellojni_HelloJni_stringFromJNI+8></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
進一步確認上一層記憶體0x80213974中的程式邏輯</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8021396c: ldmia r9, {r2, r3}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213970: ldr r12, [r4, #8]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213974: blx r12 =>由此跳到Java_com_example_hellojni_HelloJni_stringFromJNI 中執行C函式庫</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213978: cmp r5, #0 ; 0x0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8021397c: ldrne r12, [r4, #12]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213980: stmneia r12, {r0, r1}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213984: ldmdb r4, {r4, r5, r6, r7, r8, r9, sp, pc}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213988: mov r5, r2, lsr #28</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8021398c: ldr r6, [r4, #4]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213990: mov r2, #0 ; 0x0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213994: ldrb r12, [r6], #1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x80213998: cmp r12, #0 ; 0x0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x8021399c: beq 0x802139c0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x802139a0: add r2, r2, #1 ; 0x1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x802139a4: cmp r12, #68 ; 0x44</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x802139a8: cmpne r12, #74 ; 0x4a</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x802139ac: bne 0x80213994</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由上述的程式碼,我們可以對應到JNI呼叫到Native Code中的實作代碼是在dalvik/vm/arch/arm/CallEABI.S 原始碼中的Lcopy_done程式碼,負責由Java World呼叫到JNI Native Code</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.Lcopy_done:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……………….</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ldmia r9, {r2-r3} @ r2/r3<- argv[0]/argv[1]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
@ call the method</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ldr ip, [r4, #8] @ func</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef __ARM_HAVE_BLX</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
blx ip</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#else</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov lr, pc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bx ip</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由此溯源,我們得知函式dvmPlatformInvoke是在Dalvik Vm中負責將Java World與Native World做一個呼叫轉換的函式. 參考dalvik/vm/arch中的實作,Android本身有提供對 arm/sh/x86/x86-atom JNI Calling Convention的組語優化,如果不是上述平台,就會透過FFI (Foreign Function Interface)(網址:<a href="http://sourceware.org/libffi/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://sourceware.org/libffi/</a> )函式庫來實作函式dvmPlatformInvoke,達成JNI介面在不同平台上的支援. FFI機制,提供一個完整的介面,讓從Interpreter端可以呼叫到原生碼的實作,包括參數的傳遞,與對不同平台的支持,參考網頁,除了Dalvik JNI介面有採用外,包括FireFox 3.6/Mac OSX/iPhone JavaScript,Ruby,Python ..etc 都有使用這個介面達成由Interpreter呼叫到原生碼的機制.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Just-In-Time Compiler</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關JIT把ByteCode轉成原生指令集的概念,前兩天也聽到同事在聊LLVM(Low level virtual machine, 網址<a href="http://llvm.org/" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://llvm.org/</a> ),這概念是把C/C++/Fortran的程式語言透過llvm-gcc轉成中介語言,之後透過LLVM轉換成執行平台原生的指令集,有關程式碼與中介語言的產生,可以透過該網站的Demo網頁<a href="http://llvm.org/demo/index.cgi" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://llvm.org/demo/index.cgi</a> 實際的操刀體驗看看.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik系統除了有Portable與Fast Intepreter實作外,還可以透過JIT 的機制,實現把Dalvik OpCode轉成原生代碼的機制,讓運作的效率可以變得更高,參考dvmMterpStdRun的實作,我們可以知道JIT在Dalvik中的入口是透過Fast Interpreter,如果你所在平台用的是Portable Interpreter,那JIT的機制也就沒有作用了.(ㄟ 也是啦,,,,Fast Interpreter就是Dalvik用組語去刻出來的加速Dalvik OpCode直譯器,如果你不是用ARM或是x86的指令集平台,或其他第三方有支援Fast Interpreter組語實作的Dalvik版本,只能採用C版本的實作,自然也不可能會有JIT機制的實作了.).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以參考如下的新聞Android 2.2 Froyo 450% Faster Than Eclair(網頁:<a href="http://www.mobiletopsoft.com/board/7646/android-2-2-froyo-450-faster-than-eclair.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.mobiletopsoft.com/board/7646/android-2-2-froyo-450-faster-than-eclair.html</a> ),在有開啟JIT的Android 2.2 Froyo版本中,可以得到比沒有開啟JIT的2.1 Eclair大約4.5倍的Dalvik應用執行效率.(分別為37.5 MFLOPS 與 6.5-7 MFLOPS).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Google的文件,JIT的技術,有很多種施行的方式,包括在載入時期編譯,安裝應用程式時編譯,函式被呼叫時編譯整個函式,或是Byte Code指令在被擷取時編譯,而編譯時,可以選擇把整個應用程式編譯,動態函式庫,針對Class的Method編譯,Trace-JIT(選擇熱點編譯),或一次只編譯一個Byte Code指令.Android在選擇JIT技術時,主要希望以符合移動,透過電池供電,最小的記憶體需求(可以參考Jazelle網頁http://www.arm.com/products/processors/technologies/jazelle.php,Java Byte Code to Native Code記憶體會膨脹4-8倍),要跟既有的Dalvik安全機制共存,快速達到效能的提升,能在既有的直譯器(Intepreter)與JIT技術間平順的過渡.一般常見的Java虛擬器(例如 SUN Java HotSpot Virtual Machine)採用的是Method-JIT,而Dalvik採用的是Trace-JIT,兩者的差別如下</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">Method JIT</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="537">1,目前最常見的JIT機制<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,透過直譯器(Interpreter)去統計出熱門的Class Method</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,編譯與最佳化以Java Class Method為單位</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,有關虛擬器對應到直譯器的資訊,只需要考慮到所走過的Method為主.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,缺點在於,所最佳化的Mehtod中,可能會包含幾乎用不到的程式碼片段,由於優化的範圍大,因此對記憶體需求較高,在函式一開始執行時,呼叫到熱門Mehtod,需要有比較長的延遲時間(等待最佳化為機械碼)</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">Trace JIT</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="537">1,透過直譯器去統計熱門的執行路徑(Execution Path)<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,會把編譯的程式碼片段串(Fragment Chain)放到轉譯的Cache中(Dalvik-jit-code-cache)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,只有最熱門的程式碼執行路徑(片段)會被編譯到,可以節省記憶體的需求,並且可以跟直譯器更緊密的結合,擁有較快速的編譯與執行效能(因為不用根據整個Method去編譯)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,每個Dalvik行程都有獨立的Dalvik虛擬器,並擁有一個Translation Cache(用來儲存編譯為機械碼的Trace段落).</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,缺點在於,優化的範圍較小,會跟直譯器互動的頻率高,並且,較難以把最佳化過的程式碼片段跨行程分享.(由於不是以Method為單位,只根據每個Mehtod中的程式碼片段優化,每個應用程式的行為差異不小,不過這有一篇交大碩士的論文<a href="http://www.cis.nctu.edu.tw/~wuuyang/papers/File-Based%20Sharing%20For%20Dynamically%20Compiled%20Code%20On%20Dalvik%20Virtual%20Machine.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.cis.nctu.edu.tw/~wuuyang/papers/File-Based%20Sharing%20For%20Dynamically%20Compiled%20Code%20On%20Dalvik%20Virtual%20Machine.pdf</a> ,有提到如何在Dalvik中跨行程分享這優化過的程式碼片段)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,Android建議把JIT視為直譯器能力的延伸</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
7,確保Trace段落,只會包含有成功執行過的Byte Code</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8,會根據使用的平台(通常為ARM),優化暫存器的使用,Load/Store指令的使用(減少需要去外部記憶體存取的成本),消除不必要的Null-Check.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
9,優化Byte Code中Loop迴圈的執行.</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
10,通常會以一個Branch的目標位址作為一個Trace區塊的頭.(以此為Trace區塊也合理,便於在Translation Cache與Interpreter之間進行跳躍).</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考這份Android文件<a href="http://www.android-app-developer.co.uk/android-app-development-docs/android-jit-compiler-androids-dalvik-vm.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.android-app-developer.co.uk/android-app-development-docs/android-jit-compiler-androids-dalvik-vm.pdf</a> ,Android Dalvik基於記憶體需求,功耗(For 移動裝置)與應用程式反應時間,選擇了Trace-JIT為實作的技術,運作的機制為,應用程式先透過Fast Interpreter載入,依據執行的位置,更新程式執行統計表格,,如果該位置沒有達到Threshold,直譯器繼續執行,直到到達下一個可能的Trace段落,再度確認統計表格,是否有達到Threshold,若達到就確認該Trace段落,是否已經有對應編譯的結果,如果有就直接跳過去執行,如果沒有就編譯該Trace段落,並加入到JIT轉譯快取(Translation Cache)中. 位於Translation中的Trace段落編譯結果,可以依據應用程式的行為彼此呼叫,如果該編譯段落的下一段Trace Fragment並不在Translation Cache中,就直接呼叫回直譯器執行該Trace Fragment,繼續Dalvik應用程式的執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ARMv5te架構下 gDvmJit.threshold = 200 (in Sorce Code compiler/codegen/arm/armv5te/ArchVariant.c),而ARMv7a架構下 gDvmJit.threshold = 40 ( compiler/codegen/arm/armv7-a/ArchVariant.c),以此來看,處理器的時脈越高,Android對於Trace區塊Threshold的要求就越低,也就是會盡可能都透過JIT編譯讓運作環境更快.(當然也表示對同一Android區塊,JIT的編譯時間越短).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考Android文件(抱歉,,我就不自己OProfile了…@_@),Dalvik JIT對Trace段落熱區的統計,可以達到有97%是落在Translation Cache(Dalvik-jit-code-cache)中(在Cache中的Trace段落可以彼此呼叫,直到遇到不在Cache中的Trace段落才需要回到Interpreter),只有3%需要透過Fast Interpreter (Libdvm.so)執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
承上,以system_server為例,在開機後20分鐘,大約有9898個Trace段落被編譯,總共佔Byte Code大小約103966bytes(平均每個Trace段落Byte Code約11bytes),編譯需要時間約6.024秒,編譯後的機械碼大小為796264 bytes (平均每個Trace段落轉成機械碼約80bytes),所涉及的Method Byte Code程式碼大小為396230 bytes(如果用Trace-JIT可以省去編譯2.8倍的ByteCode範圍),相對於省去的JIT機械碼大小就更可觀了(Method Byte Code程式碼大小:396230 bytes 乘上7倍(約80/11)=2773610bytes,約可省下編譯後約1.977364MB).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dalvik在選擇JIT Trace區塊的時候,會在以下OpCode中進行Profile的統計,找出熱門的執行Trace區塊(參考 dalvik/vm/mterp/out/InterpAsm-armv5te.S實作),作為Trace區塊的Head.</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">指令集名稱</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">編碼</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_GOTO</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x28</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_GOTO_16</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x29</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_GOTO_32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x2a</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_PACKED_SWITCH</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x2b</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_SPARSE_SWITCH</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x2c</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_EQ</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x32</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_NE</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x33</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_LT</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x34</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_GE</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x35</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_GT</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x36</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_LE</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x37</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_EQZ</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x38</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_NEZ</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x39</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_LTZ</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x3a</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_GEZ</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x3b</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_GTZ</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x3c</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="247">OP_IF_LEZ</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="143">0x3d</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們舉實際的例子來說明,不過首先定義一下,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在ARM EABI GCC編譯器中,對於ARM暫存器的識別名稱</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">暫存器</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">識別名稱</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">說明</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r10</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">sl</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">seems to be generally available</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r11</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">fp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">is used by gcc (unless -fomit-frame-pointer is set)</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r12</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">ip</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">is scratch — not preserved across method calls</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r13</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">sp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">should be managed carefully in case a signal arrives</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r14</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">lr</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">must be preserved</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r15</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">pc</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">can be tinkered with directly</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Fast Interpreter中,對於ARM暫存器的使用與識別名稱</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">暫存器</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">識別名稱</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">說明</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r4</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">rPC</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">interpreted program counter, used for fetching instructions</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r5</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">rFP</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">interpreted frame pointer, used for accessing locals and args</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r6</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">rGLUE</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">MterpGlue pointer</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r7</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">rINST</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">first 16-bit code unit of current instruction</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="93">r8</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">rIBASE</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="455">interpreted instruction base pointer, used for computed goto</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
還有參考dalvik/vm/Globals.h 中對於gDvmJit的宣告 “extern struct DvmJitGlobals gDvmJit;”,其中 DvmJitGlobals定義了JIT運作時,所需的相關變數與狀態資訊. 以及dalvik/vm/Thread.h中對於Thread的宣告, 建議可以一併理解.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考 dalvik/vm/mterp/common/asm-constants.h中,關於組語中會用到的變數定義,同時參考dalvik/vm/mterp/Mterp.h 中的宣告 “typedef InterpState MterpGlue;” 與在原始碼 dalvik/vm/interp/InterpDefs.h中關於 “typedef struct InterpState”的原型,我定義幾個在後續說明時,會用到的MterpGlue struct參數名稱與說明</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123"><strong>ARM </strong><strong>組語中的名稱</strong><strong></strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="146"><strong>C</strong><strong>程式碼中的變數名稱</strong><strong></strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="375"><strong>說明</strong><strong></strong></td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">offGlue_pJitProfTable</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="146">pJitProfTable</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="375">Array of profile threshold counters</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">offGlue_jitThreshold</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="146">jitThreshold</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="375">為判斷該目標位置,是否已達可進行JIT編譯為原生碼的要求,以筆者手中的版本來說,armv5te-vfp/armv5te定義為200,而armv7-a-neon/armv7-a定義為40即達可進行JIT編譯的門檻.</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="146">pJitEntryTable</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="375">會透過JIT Hash機制,用來儲存在Fast Interpret中有被編譯為原生碼的目標位置Trace段落.</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">offThread_inJitCodeCache</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="146">inJitCodeCache</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="375">相對於每個Dalvik Thread,用來儲存對應的Trace區塊編譯後的原生碼記憶體位址</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">offGlue_jitState</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="146">jitState</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="375">設定Debug或要取Trace區塊時,Interpreter所在的狀態,可以包括以下的屬性<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitNot = 0, // Non-JIT related reasons */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitTSelectRequest = 1, // Request a trace (subject to filtering)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitTSelectRequestHot = 2, // Request a hot trace (bypass the filter)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitSelfVerification = 3, // Self Verification Mode</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* Operational states in the debug interpreter */</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitTSelect = 4, // Actively selecting a trace</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitTSelectEnd = 5, // Done with the trace – wrap it up</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitSingleStep = 6, // Single step interpretation</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitSingleStepEnd = 7, // Done with single step, ready return to mterp</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kJitDone = 8, // Ready to leave the debug interpreter</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="146">InterpEntry</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="375">組語的宣告<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
MTERP_CONSTANT(kInterpEntryInstr, 0)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
MTERP_CONSTANT(kInterpEntryReturn, 1)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
MTERP_CONSTANT(kInterpEntryThrow, 2)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
MTERP_CONSTANT(kInterpEntryResume, 3)</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
C的宣告</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kInterpEntryInstr = 0, // continue to next instruction</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kInterpEntryReturn = 1, // jump to method return</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kInterpEntryThrow = 2, // jump to exception throw</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
kInterpEntryResume = 3, // Resume after single-step</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="123">offGlue_entryPoint</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="146">entryPoint</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="375">用來儲存所要去的Interpreter</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來,進行流程上的說明,在OP_GOTO中,如果有加入JIT的支援就會,加入這段Code (我會把認為流程上可以忽略的Code “….”掉)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r0, rINST, lsl #16 @ r0<- AAxx0000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
movs r9, r0, asr #24 @ r9<- ssssssAA (sign-extended)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r9, r9, lsl #1 @ r9<- byte offset<strong><span style="text-decoration-line: underline;">=>r9</span></strong><strong><span style="text-decoration-line: underline;">儲存Goto</span></strong><strong><span style="text-decoration-line: underline;">要跳去的Offset</span></strong><strong><span style="text-decoration-line: underline;">值</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">如果r9</span></strong><strong><span style="text-decoration-line: underline;">為負數,</span></strong><strong><span style="text-decoration-line: underline;">表示會往低位址跳,</span></strong><strong><span style="text-decoration-line: underline;">會跳到函式 common_backwardBranch</span></strong><strong><span style="text-decoration-line: underline;">中執行</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bmi common_backwardBranch @ backward branch, do periodic checks</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">如果r9</span></strong><strong><span style="text-decoration-line: underline;">為正數,</span></strong><strong><span style="text-decoration-line: underline;">就繼續執行</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#if defined(WITH_JIT)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_JIT_PROF_TABLE(r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FETCH_ADVANCE_INST_RB(r9) @ update rPC, load rINST</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp r0,#0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bne common_updateProfile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_INST_OPCODE(ip) @ extract opcode from rINST</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GOTO_OPCODE(ip) @ jump to next instruction</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#else</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中函式common_backwardBranch的實作如下,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
common_backwardBranch:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r0, #kInterpEntryInstr</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#if defined(WITH_JIT)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_JIT_PROF_TABLE(r0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FETCH_ADVANCE_INST_RB(r9) @ update rPC, load rINST</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp r0,#0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bne common_updateProfile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_INST_OPCODE(ip)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GOTO_OPCODE(ip)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#else</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
巨集 FETCH_ADVANCE_INST_RB(宣告為#define FETCH_ADVANCE_INST_RB(_reg) ldrh rINST, [rPC, _reg]!),會把帶入的GOTO目標偏移植(Offset)當做rPC(rPC為Fast Interpreter中的Program Counter)的偏移植,並把指令存在rINST,與更新下一個指令位置到rPC中. 巨集GET_JIT_PROF_TABLE (宣告為 #define GET_JIT_PROF_TABLE(_reg) ldr _reg,[rGLUE,#offGlue_pJitProfTable]), 會傳回目前Profile Threshold Counters表格的記憶體位置,如果該值為0,表示目前並沒有啟動指令Profiling Threshold的機制,就執行原本Fast Interpreter的流程,如果該值不為0,就表示JIT的Profiling Threshold機制有開啟,就跳到函式common_updateProfile進行處理. 如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
common_updateProfile:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=>rPC</span></strong><strong><span style="text-decoration-line: underline;">儲存的是GOTO</span></strong><strong><span style="text-decoration-line: underline;">要去執行的目標位置</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
eor r3,rPC,rPC,lsr #12 @ cheap, but fast hash function</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">在筆者ARM_ARCH_5TE</span></strong><strong><span style="text-decoration-line: underline;">組態中,JIT_PROF_SIZE_LOG_2=9,</span></strong><strong><span style="text-decoration-line: underline;">其它平台為11</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lsl r3,r3,#(32 – JIT_PROF_SIZE_LOG_2) @ shift out excess bits</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">以在Fast Interpreter</span></strong><strong><span style="text-decoration-line: underline;">中的Program Counter</span></strong><strong><span style="text-decoration-line: underline;">對Profile Threshold Counters</span></strong><strong><span style="text-decoration-line: underline;">表格(</span></strong><strong><span style="text-decoration-line: underline;">位置在r0)</span></strong><strong><span style="text-decoration-line: underline;">做Hash,</span></strong><strong><span style="text-decoration-line: underline;">然後把目前目標位置的Threshold</span></strong><strong><span style="text-decoration-line: underline;">值,</span></strong><strong><span style="text-decoration-line: underline;">放到r1</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ldrb r1,[r0,r3,lsr #(32 – JIT_PROF_SIZE_LOG_2)] @ get counter</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">把rINST & 0xff </span></strong><strong><span style="text-decoration-line: underline;">存到 r12</span></strong><strong><span style="text-decoration-line: underline;">中,</span></strong><strong><span style="text-decoration-line: underline;">成為一個 Dalvik OpCode</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_INST_OPCODE(ip)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
subs r1,r1,#1 @ decrement counter</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
strb r1,[r0,r3,lsr #(32 – JIT_PROF_SIZE_LOG_2)] @ and store it</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">如果r1</span></strong><strong><span style="text-decoration-line: underline;">不為0,</span></strong><strong><span style="text-decoration-line: underline;">就直接跳到該Dalvik OpCode</span></strong><strong><span style="text-decoration-line: underline;">所在的位址,</span></strong><strong><span style="text-decoration-line: underline;">表示該目標位置尚未達Threshold</span></strong><strong><span style="text-decoration-line: underline;">的要求,</span></strong><strong><span style="text-decoration-line: underline;">還是執行Fast Interpreter</span></strong><strong><span style="text-decoration-line: underline;">的原本機制,</span></strong><strong><span style="text-decoration-line: underline;">不編譯為原生碼.</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GOTO_OPCODE_IFNE(ip) @ if not threshold, fallthrough otherwise */ (CPSR.Z=0)<br /><strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">如果r1</span></strong><strong><span style="text-decoration-line: underline;">為0,</span></strong><strong><span style="text-decoration-line: underline;">就繼續執行,</span></strong><strong><span style="text-decoration-line: underline;">根據Trace</span></strong><strong><span style="text-decoration-line: underline;">區塊,</span></strong><strong><span style="text-decoration-line: underline;">進行編譯的流程.</span></strong>………………………..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">取得目前平台預設的Threshold</span></strong><strong><span style="text-decoration-line: underline;">數值</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_JIT_THRESHOLD(r1)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ldr r10, [rGLUE, #offGlue_self] @ callee saved r10 <- glue->self</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">重設該目標位置的Threshold Counter,ARMv5</span></strong><strong><span style="text-decoration-line: underline;">預設是200,ARMv7</span></strong><strong><span style="text-decoration-line: underline;">預設是40</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
strb r1,[r0,r3,lsr #(32 – JIT_PROF_SIZE_LOG_2)] @ reset counter</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">把Fast Interpreter</span></strong><strong><span style="text-decoration-line: underline;">要去執行的目標位置,</span></strong><strong><span style="text-decoration-line: underline;">存到Interpreted Frame(Stack)</span></strong><strong><span style="text-decoration-line: underline;">中</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
EXPORT_PC()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r0,rPC</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bl dvmJitGetCodeAddr @ r0<- dvmJitGetCodeAddr(rPC)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">呼叫函式dvmJitGetCodeAddr ,</span></strong><strong><span style="text-decoration-line: underline;">如果位於Fast Interpreter</span></strong><strong><span style="text-decoration-line: underline;">的Program Counter</span></strong><strong><span style="text-decoration-line: underline;">已經有被編譯過,</span></strong><strong><span style="text-decoration-line: underline;">並儲存在Translation Cache</span></strong><strong><span style="text-decoration-line: underline;">中,</span></strong><strong><span style="text-decoration-line: underline;">就傳回對應的記憶體位置</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
str r0, [r10, #offThread_inJitCodeCache] @ set the inJitCodeCache flag</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">把編譯過的Code Cache</span></strong><strong><span style="text-decoration-line: underline;">記憶體位址儲存在#offGlue_self</span></strong><strong><span style="text-decoration-line: underline;">中的#offThread_inJitCodeCache</span></strong><strong><span style="text-decoration-line: underline;">欄位中</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r1, rPC @ arg1 of translation may need this</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov lr, #0 @ in case target is HANDLER_INTERPRET</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp r0,#0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">如果r0</span></strong><strong><span style="text-decoration-line: underline;">為0,</span></strong><strong><span style="text-decoration-line: underline;">表示尚未編譯過,</span></strong><strong><span style="text-decoration-line: underline;">反之表示編譯過,</span></strong><strong><span style="text-decoration-line: underline;">存在Translation Cache</span></strong><strong><span style="text-decoration-line: underline;">中</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#if !defined(WITH_SELF_VERIFICATION)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……………</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#else</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong><span style="text-decoration-line: underline;">=></span></strong><strong><span style="text-decoration-line: underline;">如果目前Fast Interpreter</span></strong><strong><span style="text-decoration-line: underline;">要去的Program Counter</span></strong><strong><span style="text-decoration-line: underline;">尚未編譯過,</span></strong><strong><span style="text-decoration-line: underline;">就設定r2</span></strong><strong><span style="text-decoration-line: underline;">為selectTrace Request</span></strong><strong><span style="text-decoration-line: underline;">然後呼叫函式common_selectTrace</span></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
moveq r2,#kJitTSelectRequest @ ask for trace selection</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
beq common_selectTrace</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/*</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* At this point, we have a target translation. However, if</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* that translation is actually the interpret-only pseudo-translation</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* we want to treat it the same as no translation.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*/</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mov r10, r0 @ save target</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bl dvmCompilerGetInterpretTemplate</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cmp r0, r10 @ special case?</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bne jitSVShadowRunStart @ set up self verification shadow space</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GET_INST_OPCODE(ip)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
GOTO_OPCODE(ip)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* no return */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
巨集GET_JIT_THRESHOLD (宣告為#define GET_JIT_THRESHOLD(_reg) ldr _reg,[rGLUE,#offGlue_jitThreshold]),巨集 EXPORT_PC(宣告為 #define EXPORT_PC() str rPC, [rFP, #(-sizeofStackSaveArea + offStackSaveArea_currentPc)]),由函式common_selectTrace會先回到函式dvmMterpStd中(為標準的mterp進入點,實作位置在 dalvik/vm/mterp/Mterp.c),並設定glue->nextMode = INTERP_DBG與傳回true,之後回到函式dvmInterpret(實作的位置在dalvik/vm/interp/Interp.c),因為選擇了Debug版本的Interpreter,呼叫進入dvmInterpretDbg(定義為#define INTERP_FUNC_NAME dvmInterpretDbg ),在函式INTERP_FUNC_NAME(實作在dalvik/vm/mterp/out/InterpC-portdbg.c),再呼叫函式dvmJitCheckTraceRequest(實作在dalvik/vm/interp/Jit.c),再透過函式setTraceConstruction進行Trace的建置,最後呼叫函式dvmCheckJit(實作在dalvik/vm/interp/Jit.c)會一次Interpreter切換週期(由Fast Interpreter切到Debug Interpreter),增加一個指令集的方式進行Trace流程的追蹤,目前一個Trace流程最多可以有64個TraceRun(MAX_JIT_RUN_LEN=64),也就是說如果你是在函式內GOTO到不同位置的話,這些路徑就會被當做個別的TraceRun,最後,放到同一個Trace流程中. 如果是在有Switch操作的函式中,TraceRun的選擇會以一個Switch內的處理指令流程為主,如果離開所在的Switch判斷,就會作為一個Trace流程的結束. 在dvmCheckJit內部會有以下的判斷依據</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,如果目前已執行Trace指令個數長度不為0,且上一次處理的指令為OP_PACKED_SWITCH 或OP_SPARSE_SWITCH,就會將Trace流程結束.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2,如果上一個指令不是GOTO,也不為INVOKE_DIRECT_EMPTY ,而屬於像是IF/Switch/Return/Invoke類的指令,也會作為一個Trace流程的結束.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3,如果上一個指令是一個Exception或是一個Self-Loop,也會作為一個Trace Run的結束 .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4,如果Trace的指令個數超過100個(JIT_MAX_TRACE_LEN=100),也會當做一個Trace流程的結束.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5,如果前一個指令為Return,也會當做一個Trace流程的結束.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當上述Trace流程結束就會把interpState->jitState 設定為 kJitTSelectEnd,或是直接進入到switch kJitTSelectEnd中,結束Trace流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在函式dvmCheckJit中會判斷,如果是第一個Trace區塊的指令,會把當前的Program Counter記錄在interpState->lastPC,然後,直接結束. 第二次進來時,會呼叫dexDecodeInstruction(實作在dalvik/libdex/InstrUtils.c)把上一次的Program Counter進行指令集的Decode,如果解碼後的指令為OP_PACKED_SWITCH或是OP_SPARSE_SWITCH,就會設定interpState->jitState = kJitTSelectEnd把Trace區塊做一個結束. 若繼續執行,就會透過函式dexGetInstrFlags(Inline函式宣告在libdex/InstrUtils.h中),並依據指令集的OpCode決定Flags為以下的值之一</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">Dalvik 指令</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">對應到的Flags狀態</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_NOP,OP_MOVE,OP_MOVE_FROM16,OP_MOVE_16,OP_MOVE_WIDE,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MOVE_WIDE_FROM16,OP_MOVE_WIDE_16,OP_MOVE_OBJECT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MOVE_OBJECT_FROM16,OP_MOVE_OBJECT_16,OP_MOVE_RESULT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MOVE_RESULT_WIDE,OP_MOVE_RESULT_OBJECT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MOVE_EXCEPTION,OP_CONST_4,OP_CONST_16,OP_CONST,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_CONST_HIGH16,OP_CONST_WIDE_16,OP_CONST_WIDE_32,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_CONST_WIDE,OP_CONST_WIDE_HIGH16,OP_FILL_ARRAY_DATA,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_CMPL_FLOAT,OP_CMPG_FLOAT,OP_CMPL_DOUBLE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_CMPG_DOUBLE,OP_CMP_LONG,OP_NEG_INT,OP_NOT_INT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_NEG_LONG,OP_NOT_LONG,OP_NEG_FLOAT,OP_NEG_DOUBLE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INT_TO_LONG,OP_INT_TO_FLOAT,OP_INT_TO_DOUBLE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_LONG_TO_INT,OP_LONG_TO_FLOAT,OP_LONG_TO_DOUBLE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_FLOAT_TO_INT,OP_FLOAT_TO_LONG,OP_FLOAT_TO_DOUBLE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_DOUBLE_TO_INT,OP_DOUBLE_TO_LONG,OP_DOUBLE_TO_FLOAT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INT_TO_BYTE,OP_INT_TO_CHAR,OP_INT_TO_SHORT,OP_ADD_INT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SUB_INT,OP_MUL_INT,OP_AND_INT,OP_OR_INT,OP_XOR_INT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SHL_INT,OP_SHR_INT,OP_USHR_INT,OP_ADD_LONG,OP_SUB_LONG,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MUL_LONG,OP_AND_LONG,OP_OR_LONG,OP_XOR_LONG,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SHL_LONG,OP_SHR_LONG,OP_USHR_LONG,OP_ADD_FLOAT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SUB_FLOAT,OP_MUL_FLOAT,OP_DIV_FLOAT,OP_REM_FLOAT</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
,OP_ADD_DOUBLE,OP_SUB_DOUBLE,OP_MUL_DOUBLE,OP_DIV_DOUBLE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_REM_DOUBLE,OP_ADD_INT_2ADDR,OP_SUB_INT_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MUL_INT_2ADDR,OP_AND_INT_2ADDR,OP_OR_INT_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_XOR_INT_2ADDR,OP_SHL_INT_2ADDR,OP_SHR_INT_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_USHR_INT_2ADDR,OP_ADD_LONG_2ADDR,OP_SUB_LONG_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MUL_LONG_2ADDR,OP_AND_LONG_2ADDR,OP_OR_LONG_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_XOR_LONG_2ADDR,OP_SHL_LONG_2ADDR,OP_SHR_LONG_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_USHR_LONG_2ADDR,OP_ADD_FLOAT_2ADDR,OP_SUB_FLOAT_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MUL_FLOAT_2ADDR,OP_DIV_FLOAT_2ADDR,OP_REM_FLOAT_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_ADD_DOUBLE_2ADDR,OP_SUB_DOUBLE_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MUL_DOUBLE_2ADDR,OP_DIV_DOUBLE_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_REM_DOUBLE_2ADDR,OP_ADD_INT_LIT16,OP_RSUB_INT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MUL_INT_LIT16,OP_AND_INT_LIT16,OP_OR_INT_LIT16,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_XOR_INT_LIT16,OP_ADD_INT_LIT8,OP_RSUB_INT_LIT8,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MUL_INT_LIT8,OP_AND_INT_LIT8,OP_OR_INT_LIT8,OP_XOR_INT_LIT8,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SHL_INT_LIT8,OP_SHR_INT_LIT8,OP_USHR_INT_LIT8</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">flags = kInstrCanContinue;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
表示這類指令會加入Trace區塊,並不會造成Exception</div>
</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_CONST_STRING,OP_CONST_STRING_JUMBO,OP_CONST_CLASS,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_MONITOR_ENTER,OP_MONITOR_EXIT,OP_CHECK_CAST,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INSTANCE_OF,OP_ARRAY_LENGTH,OP_NEW_INSTANCE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_NEW_ARRAY,OP_FILLED_NEW_ARRAY,OP_FILLED_NEW_ARRAY_RANGE</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
,OP_AGET,OP_AGET_BOOLEAN,OP_AGET_BYTE,OP_AGET_CHAR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_AGET_SHORT,OP_AGET_WIDE,OP_AGET_OBJECT,OP_APUT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_APUT_BOOLEAN,OP_APUT_BYTE,OP_APUT_CHAR,OP_APUT_SHORT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_APUT_WIDE,OP_APUT_OBJECT,OP_IGET,OP_IGET_BOOLEAN,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_IGET_BYTE,OP_IGET_CHAR,OP_IGET_SHORT,OP_IGET_WIDE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_IGET_OBJECT,OP_IPUT,OP_IPUT_BOOLEAN,OP_IPUT_BYTE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_IPUT_CHAR,OP_IPUT_SHORT,OP_IPUT_WIDE,OP_IPUT_OBJECT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SGET,OP_SGET_BOOLEAN,OP_SGET_BYTE,OP_SGET_CHAR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SGET_SHORT,OP_SGET_WIDE,OP_SGET_OBJECT,OP_SPUT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SPUT_BOOLEAN,OP_SPUT_BYTE,OP_SPUT_CHAR,OP_SPUT_SHORT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_SPUT_WIDE,OP_SPUT_OBJECT,OP_DIV_INT,OP_REM_INT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_DIV_LONG,OP_REM_LONG,OP_DIV_INT_2ADDR,OP_REM_INT_2ADDR,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_DIV_LONG_2ADDR,OP_REM_LONG_2ADDR,OP_DIV_INT_LIT16,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_REM_INT_LIT16,OP_DIV_INT_LIT8,OP_REM_INT_LIT8,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_EXECUTE_INLINE,OP_EXECUTE_INLINE_RANGE,OP_IGET_QUICK,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_IGET_WIDE_QUICK,OP_IGET_OBJECT_QUICK,OP_IPUT_QUICK,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_IPUT_WIDE_QUICK,OP_IPUT_OBJECT_QUICK</div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">flags = kInstrCanContinue | kInstrCanThrow;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
表示這類指令會加入Trace區塊,但有可能造成Exception</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_INVOKE_VIRTUAL,OP_INVOKE_VIRTUAL_RANGE,OP_INVOKE_SUPER,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INVOKE_SUPER_RANGE,OP_INVOKE_DIRECT,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INVOKE_DIRECT_RANGE,OP_INVOKE_STATIC,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INVOKE_STATIC_RANGE,OP_INVOKE_INTERFACE,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INVOKE_INTERFACE_RANGE,OP_INVOKE_VIRTUAL_QUICK,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INVOKE_VIRTUAL_QUICK_RANGE,OP_INVOKE_SUPER_QUICK,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_INVOKE_SUPER_QUICK_RANGE,OP_INVOKE_DIRECT_EMPTY</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">flags = kInstrCanContinue | kInstrCanThrow | kInstrInvoke;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
表示這類指令會加入Trace區塊,有機會發生Exception或是進行外部呼叫</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_RETURN_VOID,OP_RETURN,OP_RETURN_WIDE,OP_RETURN_OBJECT</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">flags = kInstrCanReturn;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
表示為Return指令</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_THROW,OP_THROW_VERIFICATION_ERROR</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">flags = kInstrCanThrow;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會觸發Exception</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_GOTO,OP_GOTO_16,OP_GOTO_32</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">flags = kInstrCanBranch | kInstrUnconditional;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
表示一個無條件的Branch動作</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_IF_EQ,OP_IF_NE,OP_IF_LT,OP_IF_GE,OP_IF_GT,OP_IF_LE,OP_IF_EQZ,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_IF_NEZ,OP_IF_LTZ,OP_IF_GEZ,OP_IF_GTZ,OP_IF_LEZ</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">flags = kInstrCanBranch | kInstrCanContinue;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
表示一個搭配條件判斷的Branch動作</div>
</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_PACKED_SWITCH,OP_SPARSE_SWITCH</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">flags = kInstrCanSwitch | kInstrCanContinue;<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
表示一個Switch判斷,如果該值不在這Switch中,會加入Trace區塊</div>
</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="397">OP_UNUSED_3E,OP_UNUSED_3F,OP_UNUSED_40,OP_UNUSED_41,<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_UNUSED_42,OP_UNUSED_43,OP_UNUSED_73,OP_UNUSED_79,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_UNUSED_7A,OP_UNUSED_E3,OP_UNUSED_E4,OP_UNUSED_E5,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_UNUSED_E6,OP_UNUSED_E7,OP_UNUSED_E8,OP_UNUSED_E9,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_UNUSED_EA,OP_UNUSED_EB,OP_BREAKPOINT,OP_UNUSED_F1,</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OP_UNUSED_FC,OP_UNUSED_FD,OP_UNUSED_FE,OP_UNUSED_FF</div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="246">these should never appear when scanning code<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
flags=0</div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
後續,呼叫dexGetInstrOrTableWidthAbs(實作在libdex/InstrUtils.c)判斷所在位置指令或是資料(PackedSwitchSignature/SparseSwitchSignature/ArrayDataSignature)的長度(指令長度的Table可以透過函式dexCreateInstrWidthTable建立),以及距離所在Class Method起始點的位置(lastPC – interpState->method->insns),如果超過該Class Method的實際實作的大小,就會觸發Assertion.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
等到完成一個Trace流程段落,會呼叫函式dvmCompilerWorkEnqueue,把這個Trace流程段落放到JIT編譯器的Queue中,之後就會由Compiler 的thread透過函式dvmCompileTrace(實作在dalvik/vm/compiler/Frontend.c)進行編譯為原生碼的動作.並重新回到函式dvmMterpStd,繼續下一個指令集的抓取與執行,直到又有指令Threshold被滿足,而進行下一次的Trace追蹤的流程. 在進行Trace追蹤的流程時,相關指令都還是會以Fast Interpreter的實作被執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要在 Android環境中支援JIT機制,必須在Dalvik編譯時加入WITH_JIT參數,可以參考dalvik/vm/Android.mk,如果所選擇的架構是armv5te (TARGET_ARCH_VARIANT:=armv5te),WITH_JIT預設會是關掉的.然後修改build/target/board/generic/system.prop加入dalvik.vm.execution-mode=int:jit (這個系統參數設定會被加入到執行時期的檔案/system/build.prop), ,就可以開始編譯支援Dalvik JIT的虛擬器.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
支援JIT的Dalvik環境除了會編譯出 libdvm.so外,參考dalvik/vm/Android.mk,在編譯Dalvik函式庫時,還會額外產生以下三個函式庫</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libdvm_sv.so (開啟Assertion與self-verification)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libdvm_assert.so (開啟Assertion與JIT Tuning)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libdvm_interp.so (這是把WITH_JIT關閉的版本)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可根據自己開發上的除錯,決定要採用的版本.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要確認所編譯的Dalvik虛擬器有無啟動JIT機制,可以在啟動後,執行dalvikvm -h 查看是否有下列參數設定</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xincludeselectedmethod</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xjitthreshold:decimalvalue</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xjitblocking</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xjitmethod:signature[,signature]* (eg Ljava/lang/String\;replace)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xjitcheckcg</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xjitverbose</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xjitprofile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-Xjitdisableopt</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>簡述</strong><strong>ADB,Emulator</strong><strong>與</strong><strong>NDK-GDB</strong><strong>運作的機制</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在非直接使用實體手機裝置透過USB開發的環境下,我們可以透過電腦上的模擬器達到便利開發的目的,根據上述的流程,我們可以看到包括abd或是ndk-gdb這些輔助開發,安裝與除錯的工具,都可以跟Emulator互通. 目前ADB,Emulator或是NDK-GDB都是透過網路TCP連線的方式進行互通. 如果使用者使用Eclipse加上ADT的環境,一開始會產生一個ADB的Daemon,監聽port 5037,而Eclipse上的ADT套件,會產生連線到ADT的port 5037. 如果有執行Emulator的話,就會由ADT連到Emulator所監聽的Port5555,與Eclipse連到Emulator所監聽的Port 5554. Emulator的Port訊息也會透過ADB Port 5037交換,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive Side Port:5037</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
==>Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
001Chost:transport:emulator-5554</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send Size Port:40280</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
==> Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OKAY</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果使用者透過ndk-gdb – -start啟動對 JNI應用除錯機制的話,就會由arm-linux-androideabi-gdb.連到adb所監聽的Port 5039進行GDB的操作動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(Receive Port:5037 Send Port:49288)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0052host:forward:tcp:5039;localfilesystem:/data/data/com.example.hellojni/debug-socket</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OKAYOKAY</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(Receive Port:5037 Send Port:49290)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0012host:transport-any</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OKAY</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
004ashell:run-as com.example.hellojni lib/gdbserver +debug-socket –attach 348</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
OKAY</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Attached; pid = 348</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Listening on sockaddr socket debug-socket</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(Receive Port:5039 Send Port:49295)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
$qSupported#37</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$PacketSize=7cf;qXfer:auxv:read+#70</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
++$Hc-1#09</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$E01#a6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$qC#b4</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$#00</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$qOffsets#4b</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$#00</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$?#3f</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$T050b:0*”00;0d:9838a0be;0f:08ebd0af;#6e</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$m9040,108#ff</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$010*”c4ca00b0010*”24cf00b0010*”3cd000b0010*”6cd200b0010*”84d300b0010*”dccb00b0010*”f4cc00b0010*”0cce00b020*%90*!210*”080*”190*”0890*!1b0*”080*”1a0*”1090*!1c0*”080*”040*”08810*!50*”ec840*!60*”4c820*!a0*”e5030*!b0*”10*”0150*”a8c400b0030*”48910*!20*”b0*”0140*”110*”170*”fc880* 110*”d4880* 120*”280*”130*”080*}0*!#a8</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$mb000c4ac,4#1a</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$b0ca00b0#48</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$mb000cab0,14#46</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$0*”00db3da0be0*”00e04901b0*%#b1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Receive: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$mb00149e0,14#f3</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Send: Return Code: 0x00000000</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
+$0*”00dc4801b0*%e0cc00b0b0ca00b0#e6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>結語</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文謹涉及Trace JIT,JNI與有關Dalvik基礎的知識,後續,會視時間從系統運作的角度,來分析Dalvik在效能加速上的議題.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
雖盡可能確保資訊的正確性,然若仍有所遺漏,還請不吝告知. 感謝!!</div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-56621359222200187592017-06-01T09:51:00.001-07:002017-06-01T09:51:57.248-07:00ARM與Cortex筆記<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
ARM與Cortex筆記</h1>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>與<span style="font-family: "Times New Roman", serif;">Cortex</span>筆記</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<a href="mailto:hlchou@mail2000.com.tw" style="color: #666666; font-weight: bold; text-decoration-line: none;">hlchou@mail2000.com.tw</a>by loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
曾聽過一段話<span style="font-family: "Times New Roman", serif;">,</span>有人問<strong>蘇格拉底</strong>為何成為雅典最有智慧的人<span style="font-family: "Times New Roman", serif;">,</span>他說<span style="font-family: "Times New Roman", serif;">:</span><span style="text-decoration-line: underline;"><strong>雅典人自以為知道什麼</strong><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span></span><span style="text-decoration-line: underline;"><strong>卻不知道其實自己什麼都不知道</strong><span style="font-family: "Times New Roman", serif;"><strong>,</strong></span></span><span style="text-decoration-line: underline;"><strong>他只知道一件事,就是他什麼都不知道</strong></span><span style="font-family: "Times New Roman", serif;">. </span>希望個人在技術領域專研<span style="font-family: "Times New Roman", serif;">,</span>也應常保此心<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
因著工作的關係<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">ARM</span>的處理器上經歷了<span style="font-family: "Times New Roman", serif;">Real-Time OS,Linux</span>相關的<span style="font-family: "Times New Roman", serif;">Porting</span>工作<span style="font-family: "Times New Roman", serif;">,</span>希望可以透過這篇文章<span style="font-family: "Times New Roman", serif;">,</span>把相關的資訊做一個整理<span style="font-family: "Times New Roman", serif;"><span style="text-decoration-line: underline;"><strong>(</strong></span></span><span style="text-decoration-line: underline;"><strong>溫故知新</strong></span><span style="font-family: "Times New Roman", serif;"><span style="text-decoration-line: underline;"><strong>),</strong></span></span>若你原本已經是<span style="font-family: "Times New Roman", serif;">ARM</span>架構的熟手<span style="font-family: "Times New Roman", serif;">,</span>本文應該幫助有限<span style="font-family: "Times New Roman", serif;">,</span>主要希望對有志於在<span style="font-family: "Times New Roman", serif;">ARM</span>相關產品開發更進一步了解的人有所幫助<span style="font-family: "Times New Roman", serif;">,</span>然個人所學有限<span style="font-family: "Times New Roman", serif;">,</span>若有不足之處<span style="font-family: "Times New Roman", serif;">,</span>還請不吝指教<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考<span style="font-family: "Times New Roman", serif;">ARM</span>的網站<span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://www.arm.com/about/company-profile/index.php" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.arm.com/about/company-profile/index.php</a></span></span>,ARM</span>公司成立於<span style="font-family: "Times New Roman", serif;">1990</span>年<span style="font-family: "Times New Roman", serif;">,</span>目前為止已經銷售了超過<span style="font-family: "Times New Roman", serif;">150</span>億個基於<span style="font-family: "Times New Roman", serif;">ARM</span>的晶片<span style="font-family: "Times New Roman", serif;">,</span>並向<span style="font-family: "Times New Roman", serif;">200</span>多加公司銷售了超過<span style="font-family: "Times New Roman", serif;">600</span>個處理器的授權<span style="font-family: "Times New Roman", serif;">,</span>並藉此收取<span style="font-family: "Times New Roman", serif;">ARM</span>晶片的授權費用<span style="font-family: "Times New Roman", serif;">,</span>目前全世界有超過<span style="font-family: "Times New Roman", serif;">95%</span>的手機以及超過<span style="font-family: "Times New Roman", serif;">25%</span>的消費性電子產品使用<span style="font-family: "Times New Roman", serif;">ARM</span>做為處理器曲<span style="font-family: "Times New Roman", serif;">7</span>超過ㄨㄛㄨㄛ<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從<span style="font-family: "Times New Roman", serif;">ARM(Advanced RISC Machines)</span>公司的名稱可以知道<span style="font-family: "Times New Roman", serif;">,</span>這是一家專注在<span style="font-family: "Times New Roman", serif;">RISC(Reduced Instruction Set computer)</span>架構的處理器公司<span style="font-family: "Times New Roman", serif;">,</span>最早的<span style="font-family: "Times New Roman", serif;">ARM1</span>原型是<span style="font-family: "Times New Roman", serif;">1985</span>年在英國劍橋的<span style="font-family: "Times New Roman", serif;">Acorn</span>計算機公司所設計<span style="font-family: "Times New Roman", serif;">,</span>並由美國的<span style="font-family: "Times New Roman", serif;">VLSI</span>公司製造<span style="font-family: "Times New Roman", serif;">,</span>也因此在<span style="font-family: "Times New Roman", serif;">Wiki</span>上看到<span style="font-family: "Times New Roman", serif;">,</span>早期<span style="font-family: "Times New Roman", serif;">ARM1,ARM2,ARM250,ARM3..</span>的處理器<span style="font-family: "Times New Roman", serif;">,</span>都被<span style="font-family: "Times New Roman", serif;">Acorn</span>這家公司採用作為計算機核心處理器<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1978/12/5,</span>物理學家赫爾曼<span style="font-family: "Times New Roman", serif;">·</span>豪澤(<span style="font-family: "Times New Roman", serif;">Hermann Hauser</span>)和工程師<span style="font-family: "Times New Roman", serif;">Chris Curry,</span>在英國康橋創辦了<span style="font-family: "Times New Roman", serif;">CPU</span>公司(<span style="font-family: "Times New Roman", serif;">Cambridge Processing Unit</span>)並在<span style="font-family: "Times New Roman", serif;">1979</span>年<span style="font-family: "Times New Roman", serif;">,CPU</span>公司改名為<span style="font-family: "Times New Roman", serif;">Acorn</span>電腦公司<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">1985</span>年<span style="font-family: "Times New Roman", serif;">,Roger Wilson</span>和<span style="font-family: "Times New Roman", serif;">Steve Furber</span>設計了他們自己的第一代<span style="font-family: "Times New Roman", serif;">32</span>位、<span style="font-family: "Times New Roman", serif;">6M Hz</span>的處理器<span style="font-family: "Times New Roman", serif;">,</span>用它做出了一台<span style="font-family: "Times New Roman", serif;">RISC</span>指令集的電腦<span style="font-family: "Times New Roman", serif;">,</span>簡稱<span style="font-family: "Times New Roman", serif;">ARM</span>(<span style="font-family: "Times New Roman", serif;">Acorn RISC Machine</span>)<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
隨後<span style="font-family: "Times New Roman", serif;">,Acorn</span>公司陷入財務困難<span style="font-family: "Times New Roman", serif;">,</span>並被<span style="font-family: "Times New Roman", serif;">Olivetti</span>收購<span style="font-family: "Times New Roman", serif;">,</span>成為一個獨立的<span style="font-family: "Times New Roman", serif;">Olivetti</span>研究子公司<span style="font-family: "Times New Roman", serif;">,1990/11/27,ARM</span>獲得蘋果公司與晶片廠商<span style="font-family: "Times New Roman", serif;">VLSI</span>的投資<span style="font-family: "Times New Roman", serif;">,</span>成為一家獨立的處理器公司<span style="font-family: "Times New Roman", serif;">,</span>在穀倉展開創業的歷程<span style="font-family: "Times New Roman", serif;">,</span>像是大家印象深刻的<span style="font-family: "Times New Roman", serif;">Apple Newton PDA,</span>用的就是<span style="font-family: "Times New Roman", serif;">ARM610</span>處理器<span style="font-family: "Times New Roman", serif;">.(</span>參考文章<span style="font-family: "Times New Roman", serif;">:<span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://www5.cnfol.com/big5/news.cnfol.com/100823/101,1587,8274016,00.shtml" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www5.cnfol.com/big5/news.cnfol.com/100823/101,1587,8274016,00.shtml</a></span></span></span>與 <span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://big5.buynow.com.cn/gate/big5/www.cnbeta.com/articles/131786.htm" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://big5.buynow.com.cn/gate/big5/www.cnbeta.com/articles/131786.htm</a></span></span> )</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
稍微考古一下<span style="font-family: "Times New Roman", serif;">,</span>目前處理器的架構中<span style="font-family: "Times New Roman", serif;">,</span>主要有<span style="font-family: "Times New Roman", serif;">1940</span>年代提出的<span style="font-family: "Times New Roman", serif;">Von Neumann</span>記憶體架構<span style="font-family: "Times New Roman", serif;">,</span>讓程式與資料共用相同的匯流排<span style="font-family: "Times New Roman", serif;">,</span>以及之後的<span style="font-family: "Times New Roman", serif;">Harvard</span>架構<span style="font-family: "Times New Roman", serif;">,</span>讓程式與資料走不同的匯流排<span style="font-family: "Times New Roman", serif;">,</span>好處在於可以同時進行程式與資料的記憶體存取動作<span style="font-family: "Times New Roman", serif;">,</span>早期的<span style="font-family: "Times New Roman", serif;">ARM7</span>跟<span style="font-family: "Times New Roman", serif;">8051</span>一般是採用<span style="font-family: "Times New Roman", serif;">Von Neumann</span>架構<span style="font-family: "Times New Roman", serif;">,</span>一塊<span style="font-family: "Times New Roman", serif;">Cache</span>供指令與資料存取<span style="font-family: "Times New Roman", serif;">,</span>而目前新的微處理器架構<span style="font-family: "Times New Roman", serif;">(</span>例如<span style="font-family: "Times New Roman", serif;">:ARM11 or Cortex A),</span>通常都採用<span style="font-family: "Times New Roman", serif;">Harvard</span>架構<span style="font-family: "Times New Roman", serif;">,</span>也就是處理器會支援<span style="font-family: "Times New Roman", serif;">I-Cache</span>與<span style="font-family: "Times New Roman", serif;">D-Cache,</span>區分指令與資料的擷取匯流排<span style="font-family: "Times New Roman", serif;">,</span>提升處理器的效率<span style="font-family: "Times New Roman", serif;">. (</span>參考文章<span style="font-family: "Times New Roman", serif;">:<span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/ARM7" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/ARM7</a></span></span> and <span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Harvard_architecture" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/Harvard_architecture</a></span></span> ).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關<span style="font-family: "Times New Roman", serif;">ARM</span>在<span style="font-family: "Times New Roman", serif;">Von Neumann</span>與<span style="font-family: "Times New Roman", serif;">Harvard</span>架構的分類<span style="font-family: "Times New Roman", serif;">,</span>也可以參考網頁<span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://stenlyho.blogspot.com/2008/08/armcpu.html" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;">http://stenlyho.blogspot.com/2008/08/armcpu.html</span></span></a></span></span><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"> ,</span></span></span><span style="font-size: x-small;">如下所示</span></div>
<dl style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;"><dd><table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 928px;"><colgroup><col width="154"></col><col width="188"></col><col width="189"></col><col width="188"></col><col width="157"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">Processor Family</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">#of pipeline stages</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><span style="font-family: "Times New Roman", serif;">Memory Organization</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">Clock Rate</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: "Times New Roman", serif;">MIPS/MHz</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">ARM6</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">3</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><span style="font-family: "Times New Roman", serif;">Von Neumann</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">25MHz</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">ARM7</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">3</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><span style="font-family: "Times New Roman", serif;">Von Neumann</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">66MHz</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: "Times New Roman", serif;">0.9</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">ARM8</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">5</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><span style="font-family: "Times New Roman", serif;">Von Neumann</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">72MHz</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: "Times New Roman", serif;">1.2</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">ARM9</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">5</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><span style="font-family: "Times New Roman", serif;">Harvard</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">200MHz</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: "Times New Roman", serif;">1.1</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">ARM10</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">6</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><span style="font-family: "Times New Roman", serif;">Harvard</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">400MHz</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: "Times New Roman", serif;">1.25</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">StrongARM</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">5</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><span style="font-family: "Times New Roman", serif;">Harvard</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">233MHz</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: "Times New Roman", serif;">1.15</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">ARM11</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">8</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="189"><span style="font-family: "Times New Roman", serif;">Von Neumann/Harvard</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">550MHz</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="font-family: "Times New Roman", serif;">1.2</span></td></tr>
</tbody></table>
</dd></dl>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>是採用<span style="font-family: "Times New Roman", serif;">RISC </span>精簡指令集 <span style="font-family: "Times New Roman", serif;">(Reduced Instruction Set Computing)</span>架構的處理器<span style="font-family: "Times New Roman", serif;">,RISC</span>架構主要選擇使用頻率較高的簡單指令<span style="font-family: "Times New Roman", serif;">,</span>避免複雜指令<span style="font-family: "Times New Roman", serif;">,</span>使用固定長度的指令編碼<span style="font-family: "Times New Roman", serif;">(</span>支援<span style="font-family: "Times New Roman", serif;">32bits,16bits</span>或<span style="font-family: "Times New Roman", serif;">16/32bits</span>混合<span style="font-family: "Times New Roman", serif;">),</span>單週期指令<span style="font-family: "Times New Roman", serif;">,</span>便於<span style="font-family: "Times New Roman", serif;">Pipeline</span>的操作執行<span style="font-family: "Times New Roman", serif;">,</span>並透過大量暫存器<span style="font-family: "Times New Roman", serif;">,</span>讓邏輯處理指令只對暫存器進行操作<span style="font-family: "Times New Roman", serif;">,</span>只有特定載入<span style="font-family: "Times New Roman", serif;">/</span>儲存的指令可以存取記憶體內容<span style="font-family: "Times New Roman", serif;">.</span>相比<span style="font-family: "Times New Roman", serif;">CISC</span>架構<span style="font-family: "Times New Roman", serif;">,</span>會隨著需求<span style="font-family: "Times New Roman", serif;">,</span>不斷的加入新的指令集<span style="font-family: "Times New Roman", serif;">,</span>使得架構越趨複雜<span style="font-family: "Times New Roman", serif;">,</span>現實應用中<span style="font-family: "Times New Roman", serif;">,</span>也並非所有的指令都是常被使用的<span style="font-family: "Times New Roman", serif;">,</span>如下<span style="font-family: "Times New Roman", serif;">,</span>以<span style="font-family: "Times New Roman", serif;">CSIC</span>架構的<span style="font-family: "Times New Roman", serif;">x86 </span>指令集為例<span style="font-family: "Times New Roman", serif;">,</span>指令集呈現不固定長度的方式<span style="font-family: "Times New Roman", serif;">,</span>如下例子<span style="font-family: "Times New Roman", serif;">,</span>有<span style="font-family: "Times New Roman", serif;">1,2,7</span>與<span style="font-family: "Times New Roman", serif;">11 bytes</span>的例子</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(1bytes)0x48 = dec eax</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(2bytes)0x89 F9= mov ecx,edi</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(7bytes)0x8B BC 24 A4 01 00 00 = mov edi,dword ptr [esp+000001A4h]</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(11bytes)0x81 BC 24 14 01 00 00 FF 00 00 00 = cmp dword ptr [esp+00000114h],0FFh</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>透過<span style="font-family: "Times New Roman", serif;">Pipeline</span>的方式加速指令集的處理<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">Pipeline</span>執行階段<span style="font-family: "Times New Roman", serif;">,</span>如果發生中斷<span style="font-family: "Times New Roman", serif;">,</span>也會把<span style="font-family: "Times New Roman", serif;">Pipeline</span>中的指令執行完畢才進入中斷<span style="font-family: "Times New Roman", serif;">,</span>如下所示<span style="font-family: "Times New Roman", serif;">ARM7</span>支援如下的<span style="font-family: "Times New Roman", serif;">3</span>階<span style="font-family: "Times New Roman", serif;">Pipeline</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #dc2300;"><strong>Fetch → Decode → Execute</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>其中</strong></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 482px;"><colgroup><col width="72"></col><col width="388"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Fetch</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="388">進行指令的擷取動作</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Decode</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="388"><span style="font-family: "Times New Roman", serif;">Thumb->ARM</span>指令<span style="font-family: "Times New Roman", serif;">Decompress,ARM</span>指令解碼<span style="font-family: "Times New Roman", serif;">,</span>暫存器選擇</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Execute</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="388">進行暫存器<span style="font-family: "Times New Roman", serif;">/</span>記憶體讀取<span style="font-family: "Times New Roman", serif;">,</span>算術邏輯運算與暫存器<span style="font-family: "Times New Roman", serif;">/</span>記憶體回寫動作</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #dc2300;"><strong></strong></span></span>每一個<span style="font-family: "Times New Roman", serif;">CPU</span>週期<span style="font-family: "Times New Roman", serif;">,</span>處理器都可以同時處理 <span style="font-family: "Times New Roman", serif;">‘Fetch’,’Decode’,’Execute’</span><span style="font-family: Arial, sans-serif;">這三個動作</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: Arial, sans-serif;">而非把一個指令從</span><span style="font-family: "Times New Roman", serif;">Fetch</span><span style="font-family: Arial, sans-serif;">開始到執行完畢後</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: Arial, sans-serif;">才處理下一個指令週期</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: Arial, sans-serif;">如下圖所示</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 541px;"><colgroup><col width="105"></col><col width="132"></col><col width="128"></col><col width="134"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105"><span style="font-family: "Times New Roman", serif;">Time</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="132"><span style="font-family: "Times New Roman", serif;">Fetch</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "Times New Roman", serif;">Decode</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="134"><span style="font-family: "Times New Roman", serif;">Execute</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105"><span style="font-family: "Times New Roman", serif;">Cycle#1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="132"><span style="font-family: "Times New Roman", serif;">Instruction#1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="134"></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105"><span style="font-family: "Times New Roman", serif;">Cycle#2</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="132"><span style="font-family: "Times New Roman", serif;">Instruction#2</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "Times New Roman", serif;">Instruction#1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="134"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105"><span style="font-family: "Times New Roman", serif;">Cycle#3</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="132"><span style="font-family: "Times New Roman", serif;">Instruction#3</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "Times New Roman", serif;">Instruction#2</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="134"><span style="font-family: "Times New Roman", serif;">Instruction#1</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105"><span style="font-family: "Times New Roman", serif;">Cycle#4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="132"><span style="font-family: "Times New Roman", serif;">Instruction#4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "Times New Roman", serif;">Instruction#3</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="134"><span style="font-family: "Times New Roman", serif;">Instruction#2</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105"><span style="font-family: "Times New Roman", serif;">Cycle#5</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="132"><span style="font-family: "Times New Roman", serif;">Instruction#5</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "Times New Roman", serif;">Instruction#4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="134"><span style="font-family: "Times New Roman", serif;">Instruction#3</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="105"><span style="font-family: "Times New Roman", serif;">Cycle#6</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="132"><span style="font-family: "Times New Roman", serif;">Instruction#6</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="128"><span style="font-family: "Times New Roman", serif;">Instruction#5</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="134"><span style="font-family: "Times New Roman", serif;">Instruction#4</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
為了避免在非載入記憶體階段<span style="font-family: "Times New Roman", serif;">,</span>讓運算指令進行記憶體的存取<span style="font-family: "Times New Roman", serif;">,</span>而導致<span style="font-family: "Times New Roman", serif;">Pipeline</span>可重疊執行的能力被破壞<span style="font-family: "Times New Roman", serif;">,ARM</span>只允許特定載入儲存指令讀寫記憶體的資料<span style="font-family: "Times New Roman", serif;">. </span>早期的<span style="font-family: "Times New Roman", serif;">ARM6,ARM7</span>有約<span style="font-family: "Times New Roman", serif;">3</span>階的<span style="font-family: "Times New Roman", serif;">Pipeline,</span>到了<span style="font-family: "Times New Roman", serif;">ARM8,ARM9</span>時<span style="font-family: "Times New Roman", serif;">,</span>約為<span style="font-family: "Times New Roman", serif;">5</span>階的<span style="font-family: "Times New Roman", serif;">Pipeline,</span>之後的<span style="font-family: "Times New Roman", serif;">ARM11</span>則為<span style="font-family: "Times New Roman", serif;">8</span>階的<span style="font-family: "Times New Roman", serif;">Pipeline,</span>不過<span style="font-family: "Times New Roman", serif;">,Pipeline</span>過深不一定就能帶來更高的效益<span style="font-family: "Times New Roman", serif;">,</span>如果程式碼的流程中遇到分支<span style="font-family: "Times New Roman", serif;">(</span>例如<span style="font-family: "Times New Roman", serif;">:Branch</span>到另一個程式區塊<span style="font-family: "Times New Roman", serif;">),</span>就會導致<span style="font-family: "Times New Roman", serif;">Pipeline</span>中的資料失效<span style="font-family: "Times New Roman", serif;">,</span>要重新進行指令<span style="font-family: "Times New Roman", serif;">Fetch</span>的動作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡單來說<span style="font-family: "Times New Roman", serif;">,Pipeline</span>就是把指令的處理分級幾個不同的步驟<span style="font-family: "Times New Roman", serif;">,</span>例如</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM9</span>支援如下的<span style="font-family: "Times New Roman", serif;">5</span>階<span style="font-family: "Times New Roman", serif;">Pipeline</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #dc2300;"><strong>Fetch → Decode → Execute→ Memory→ Write Back</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 528px;"><colgroup><col width="115"></col><col width="391"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Fetch</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">進行指令的擷取<span style="font-family: "Times New Roman", serif;">(Fetch)</span>動作</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Decode</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">進行<span style="font-family: "Times New Roman", serif;">ARM/Thumb</span>指令解碼與暫存器的讀取</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Execute</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">進行邏輯運算與記憶體存取位址計算動作</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Memory</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">讀取或寫回記憶體資料</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="115"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Write Back</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">將運算或是<span style="font-family: "Times New Roman", serif;">Load</span>結果回寫暫存器中</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM10</span>之後<span style="font-family: "Times New Roman", serif;">,</span>有支援<span style="font-family: "Times New Roman", serif;">Branch Prediction,</span>以減少在<span style="font-family: "Times New Roman", serif;">Pipeline</span>執行期間<span style="font-family: "Times New Roman", serif;">,</span>因為<span style="font-family: "Times New Roman", serif;">Branch</span>動作導致<span style="font-family: "Times New Roman", serif;">Pipeline</span>失效 <span style="font-family: "Times New Roman", serif;">Flush</span>的機會<span style="font-family: "Times New Roman", serif;">,</span>支援如下的<span style="font-family: "Times New Roman", serif;">6</span>階<span style="font-family: "Times New Roman", serif;">Pipeline</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #dc2300;"><strong>Fetch→ Issue → Decode → Execute→ Memory→ Write Back</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 530px;"><colgroup><col width="117"></col><col width="391"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Fetch</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">進行<span style="font-family: "Times New Roman", serif;">Branch Predictor</span>指令分支預測<span style="font-family: "Times New Roman", serif;">,</span>指令位址計算<span style="font-family: "Times New Roman", serif;">,</span>與指令的擷取<span style="font-family: "Times New Roman", serif;">(Fetch)</span>動作</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Issue</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391"><span style="font-family: "Times New Roman", serif;">ARM/Thumb</span>指令解碼<span style="font-family: "Times New Roman", serif;">,</span>若非<span style="font-family: "Times New Roman", serif;">ARM/Thumb</span>有效指令<span style="font-family: "Times New Roman", serif;">,</span>就透過<span style="font-family: "Times New Roman", serif;">Coprocessor Signal</span>判斷是否為<span style="font-family: "Times New Roman", serif;">Coprocessor</span>指令</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Decode</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">暫存器的讀取<span style="font-family: "Times New Roman", serif;">,Result Forward,ScoreBoard</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Execute</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">進行算術邏輯運算與<span style="font-family: "Times New Roman", serif;">Branch/Data</span>存取記憶體位址計算<span style="font-family: "Times New Roman", serif;">,</span>乘法運算</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Memory</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">讀取或寫回記憶體資料<span style="font-family: "Times New Roman", serif;">,Coprocessor</span>資料存取<span style="font-family: "Times New Roman", serif;">,</span>乘法相加處理</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Write Back</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="391">將運算或是<span style="font-family: "Times New Roman", serif;">Load</span>結果回寫暫存器中</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM11</span>採用<span style="font-family: "Times New Roman", serif;">Scalar</span>架構的<span style="font-family: "Times New Roman", serif;">Pipeline,</span>並在<span style="font-family: "Times New Roman", serif;">Issue</span>階段支援<span style="font-family: "Times New Roman", serif;">ALU(arithmetic logic unit),MAC(multiply/accumulate)</span>與<span style="font-family: "Times New Roman", serif;">Load/Store</span>分種<span style="font-family: "Times New Roman", serif;">Pipeline</span>的流水線<span style="font-family: "Times New Roman", serif;">,</span>可以在一個<span style="font-family: "Times New Roman", serif;">Cycle</span>分發一個對應的處理器動作到一個<span style="font-family: "Times New Roman", serif;">Pipeline,</span>如下所示的<span style="font-family: "Times New Roman", serif;">8</span>階<span style="font-family: "Times New Roman", serif;">Scalar Pipeline (ARM1156T2-S</span>支援<span style="font-family: "Times New Roman", serif;">9</span>階的<span style="font-family: "Times New Roman", serif;">Pipeline,</span>其中<span style="font-family: "Times New Roman", serif;">Fetch Pipeline</span>擴充為<span style="font-family: "Times New Roman", serif;">3</span>階<span style="font-family: "Times New Roman", serif;">,</span>細節就不在這討論<span style="font-family: "Times New Roman", serif;">,</span>可以參考網頁<span style="font-family: "Times New Roman", serif;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0338g/I1002919.html)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #dc2300;"><strong>Fetch#1→ Fetch#2→ Decode→ISS (ALU Pipeline)→ Shifter→ALU→ SAT→ Write Back</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>______________________________(MAC Pipeline) → MAC1→MAC2→ MAC3→ Write Back</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>______________________________(Load/Store Pipeline)→ LS Add→DC1→ DC2→ Write Back</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="color: #dc2300;"><strong></strong></span></span>跟之前版本相比<span style="font-family: "Times New Roman", serif;">ARM11</span>用了兩個<span style="font-family: "Times New Roman", serif;">Fetch Pipeline</span>階段去支援兩種指令分支預測<span style="font-family: "Times New Roman", serif;">(Branch Prediction)</span>的機制<span style="font-family: "Times New Roman", serif;">,</span>第一個<span style="font-family: "Times New Roman", serif;">Fetch Pipeline</span>階段會根據歷史紀錄進行動態的指令分支預測<span style="font-family: "Times New Roman", serif;">(Dynamic Branch Prediction),</span>總共紀錄<span style="font-family: "Times New Roman", serif;">64</span>筆<span style="font-family: "Times New Roman", serif;">,4</span>種狀態<span style="font-family: "Times New Roman", serif;">(Strongly taken,Weakly taken,Weakly not-taken and Strongly non-taken)</span>的分支<span style="font-family: "Times New Roman", serif;">((Branch)</span>目標記憶體位址快取<span style="font-family: "Times New Roman", serif;">(BTAC,Branch-Target Address Cache),</span>紀錄近期指令分支的情況<span style="font-family: "Times New Roman", serif;">. </span>第二個<span style="font-family: "Times New Roman", serif;">Fetch Pipeline</span>階段<span style="font-family: "Times New Roman", serif;">,</span>進行靜態的指令分支預測<span style="font-family: "Times New Roman", serif;">(Static Branch Prediction),</span>會處理不在第一階段範圍中的分支預測記憶體位址<span style="font-family: "Times New Roman", serif;">. </span>命中率高的指令分支預測<span style="font-family: "Times New Roman", serif;">(Branch Prediction)</span>可以避免<span style="font-family: "Times New Roman", serif;">Pipeline</span>失效重置的問題<span style="font-family: "Times New Roman", serif;">,</span>讓處理器的運作效率更高<span style="font-family: "Times New Roman", serif;">. </span>根據參考的資料<span style="font-family: "Times New Roman", serif;">,ARM11</span>的<span style="font-family: "Times New Roman", serif;">Dynamic</span>與<span style="font-family: "Times New Roman", serif;">Static Branch Prediction</span>在一般執行情況下可以有約<span style="font-family: "Times New Roman", serif;">85%</span>的命中率<span style="font-family: "Times New Roman", serif;">,</span>大多數的情況可以介於<span style="font-family: "Times New Roman", serif;">80%-95%</span>之間<span style="font-family: "Times New Roman", serif;">(</span>取決於程式碼的大小<span style="font-family: "Times New Roman", serif;">).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡介如下<span style="font-family: "Times New Roman", serif;">,</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 854px;"><colgroup><col width="20"></col><col width="56"></col><col width="91"></col><col width="108"></col><col width="61"></col><col width="177"></col><col width="60"></col><col width="199"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="font-family: "Times New Roman", serif;">#1</span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Fetch#1</strong></span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="645">進行<span style="font-family: "Times New Roman", serif;">Dynamic Branch Prediction,</span>指令位址計算<span style="font-family: "Times New Roman", serif;">,</span>與指令的擷取<span style="font-family: "Times New Roman", serif;">(Fetch)</span>動作</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="font-family: "Times New Roman", serif;">#2</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Fetch#2</strong></span></span></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="645">進行<span style="font-family: "Times New Roman", serif;">Static Branch Prediction</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="font-family: "Times New Roman", serif;">#3</span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Decode</strong></span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="645"><span style="font-family: "Times New Roman", serif;">ARM/Thumb</span>指令解碼<span style="font-family: "Times New Roman", serif;">,</span>若非<span style="font-family: "Times New Roman", serif;">ARM/Thumb</span>有效指令<span style="font-family: "Times New Roman", serif;">,</span>就透過<span style="font-family: "Times New Roman", serif;">Coprocessor Signal</span>判斷是否為<span style="font-family: "Times New Roman", serif;">Coprocessor</span>指令<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Static BPR Stack</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="font-family: "Times New Roman", serif;">#4</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>ISS<br />(Instruction Issue)</strong></span></span></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="645">暫存器的讀取<span style="font-family: "Times New Roman", serif;">,</span>與指令執行路徑分派<span style="font-family: "Times New Roman", serif;">,</span>有三條路徑邏輯運算<span style="font-family: "Times New Roman", serif;">ALU Pipeline,</span>乘法累加<span style="font-family: "Times New Roman", serif;">MAC Pipeline,</span>與資料存取<span style="font-family: "Times New Roman", serif;">Load/Store Pipeline.</span></td></tr>
<tr valign="TOP"><td bgcolor="#999999" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="305"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ALU Pipeline</strong></span></span></span></td><td bgcolor="#999999" colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>MAC Pipeline</strong></span></span></span></td><td bgcolor="#999999" colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="269"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/Store Pipeline</strong></span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="font-family: "Times New Roman", serif;">#5</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Shifter</strong></span></span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="209"><span style="font-size: xx-small;">對邏輯運算指令操作單元</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">(operand)</span></span><span style="font-size: xx-small;">進行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Shift</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>MAC1</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-size: xx-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span><span style="font-size: xx-small;">階段乘法累加操作</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="60"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>LS Add</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="199"><span style="font-size: xx-small;">計算產生</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Load/Store</span></span><span style="font-size: xx-small;">操作的記憶體位址</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="font-family: "Times New Roman", serif;">#6</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ALU</strong></span></span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="209"><span style="font-size: xx-small;">進行整數算術邏輯運算</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>MAC2</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-size: xx-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2</span></span><span style="font-size: xx-small;">階段乘法累加操作</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="60"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>DC1</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="199"><span style="font-size: xx-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span><span style="font-size: xx-small;">階段</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Data Cache</span></span><span style="font-size: xx-small;">存取</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="font-family: "Times New Roman", serif;">#7</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>SAT</strong></span></span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="209"><span style="font-size: xx-small;">儲存運算結果</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>MAC3</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="177"><span style="font-size: xx-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">3</span></span><span style="font-size: xx-small;">階段乘法累加操作</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="60"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>DC2</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="199"><span style="font-size: xx-small;">第</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2</span></span><span style="font-size: xx-small;">階段</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Data Cache</span></span><span style="font-size: xx-small;">存取</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="font-family: "Times New Roman", serif;">#8</span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="157"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><strong>Write Back</strong></span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="645">將運算或是<span style="font-family: "Times New Roman", serif;">Load</span>結果回寫暫存器中</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來<span style="font-family: "Times New Roman", serif;">,</span>介紹<span style="font-family: "Times New Roman", serif;">ARM Cortext A</span>系列的架構<span style="font-family: "Times New Roman", serif;">,</span>在這架構下<span style="font-family: "Times New Roman", serif;">ARM</span>導入了<span style="font-family: "Times New Roman", serif;">Superscalar </span>架構的<span style="font-family: "Times New Roman", serif;">Pipeline,</span>讓處理器可以在一個週期平行處理一個以上的指令集<span style="font-family: "Times New Roman", serif;">,</span>以<span style="font-family: "Times New Roman", serif;">Cortex A8</span>為例<span style="font-family: "Times New Roman", serif;">,</span>支援<span style="font-family: "Times New Roman", serif;">13</span>階的整數<span style="font-family: "Times New Roman", serif;">Pipeline</span>與<span style="font-family: "Times New Roman", serif;">10</span>階的<span style="font-family: "Times New Roman", serif;">NEON</span>多媒體指令集<span style="font-family: "Times New Roman", serif;">Pipeline,</span>以整數處理的指令集為例<span style="font-family: "Times New Roman", serif;">,Cortex A8</span>支援<span style="font-family: "Times New Roman", serif;">Dual-Issue,In-Order Pipeline,</span>不同於之前的<span style="font-family: "Times New Roman", serif;">ARM</span>核心一次只能處理一個整數處理指令集<span style="font-family: "Times New Roman", serif;">,Cortex A8</span>可以同時<span style="font-family: "Times New Roman", serif;">Issue</span>兩個整數處理指令集<span style="font-family: "Times New Roman", serif;">,</span>並在一個週期中<span style="font-family: "Times New Roman", serif;">,</span>透過兩個整數算術邏輯單元<span style="font-family: "Times New Roman", serif;">Pipeline</span>平行處理這兩個指令集<span style="font-family: "Times New Roman", serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 887px;"><colgroup><col width="15"></col><col width="15"></col><col width="16"></col><col width="17"></col><col width="18"></col><col width="17"></col><col width="17"></col><col width="20"></col><col width="71"></col><col width="35"></col><col width="37"></col><col width="31"></col><col width="27"></col><col width="23"></col><col width="59"></col><col width="26"></col><col width="23"></col><col width="47"></col><col width="19"></col><col width="23"></col><col width="21"></col><col width="20"></col><col width="19"></col><col width="29"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td colspan="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="489"><span style="font-family: "Times New Roman", serif;"><strong>13-Stage Integer Pipeline</strong></span></td><td colspan="10" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="376"><span style="font-family: "Times New Roman", serif;"><strong>10-Stage NEON Pipeline</strong></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="color: #999999;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">F#0</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="15"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">F#1</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="16"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">F#2</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">D#0</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="18"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">D#1</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">D#2</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="17"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">D#3</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">D#4</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">E#0</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="35"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">E#1</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="37"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">E#2</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="31"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">E#3</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="27"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">E#4</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">E#5</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="59"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">M#0</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="26"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">M#1</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">M#2</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="47"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">M#3</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="19"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">N#1</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="23"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">N#2</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="21"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">N#3</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="20"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">N#4</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="19"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">N#5</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="29"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">N#6</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td colspan="3" rowspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="66"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Instruction Fetch</span></span></td><td colspan="5" rowspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Instruction Decode</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">with </span><span style="color: red;"><span style="font-size: xx-small;"><strong>Dual-Issues</strong></span></span></span></div>
</td><td rowspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Architectural</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Register</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">File</span></span></div>
</td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="193"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ALU/MUL Pipeline 0</span></span></td><td rowspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="59"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">NEON<br />Instruction</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Queue</span></span></div>
</td><td colspan="2" rowspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="59"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">NEON<br />Instruction</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Decode</span></span></div>
</td><td rowspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="47"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">NEON<br />Register</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">File</span></span></div>
</td><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Integer ALU Pipe</span></span></td></tr>
<tr valign="TOP"><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="193"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ALU Pipeline 1</span></span></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Integer MUL Pipe</span></span></td></tr>
<tr class="alt" valign="TOP"><td colspan="5" rowspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="193"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Load/Store Pipeline 0 or 1</span></span></td><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Integer Shift Pipe</span></span></td></tr>
<tr valign="TOP"><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None-IEEE FP Add Pipe</span></span></td></tr>
<tr class="alt" valign="TOP"><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None-IEEE FP Mul Pipe</span></span></td></tr>
<tr valign="TOP"><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">IEEE FP Engine</span></span></td></tr>
<tr class="alt" valign="TOP"><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Load/Store Permute Pipe</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在<span style="font-family: "Times New Roman", serif;">Cortex A8</span>架構下<span style="font-family: "Times New Roman", serif;">,</span>有兩個 <span style="font-family: "Times New Roman", serif;">ALU Pipeline,ALU 0</span>與<span style="font-family: "Times New Roman", serif;">ALU1</span>是對稱的<span style="font-family: "Times New Roman", serif;">,</span>可以同時處理兩個整數邏輯運算<span style="font-family: "Times New Roman", serif;">,</span>由於<span style="font-family: "Times New Roman", serif;">Pipeline</span>的特性<span style="font-family: "Times New Roman", serif;">,</span>在使用上<span style="font-family: "Times New Roman", serif;">,</span>乘法需求的指令會跟<span style="font-family: "Times New Roman", serif;">ALU 0</span>成對 <span style="font-family: "Times New Roman", serif;">(</span>也就是說在這條<span style="font-family: "Times New Roman", serif;">Pipeline 0</span>連續處理有關整數邏輯運算與乘法相關的指令<span style="font-family: "Times New Roman", serif;">),</span>而<span style="font-family: "Times New Roman", serif;">Load/Store </span>的指令<span style="font-family: "Times New Roman", serif;">,</span>則適合跟<span style="font-family: "Times New Roman", serif;">ALU 0</span>或<span style="font-family: "Times New Roman", serif;">1</span>兩者任一一起成對運作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其中</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 936px;"><colgroup><col width="95"></col><col width="77"></col><col width="38"></col><col width="80"></col><col width="86"></col><col width="9"></col><col width="61"></col><col width="88"></col><col width="0"></col><col width="0"></col><col width="66"></col><col width="107"></col><col width="101"></col></colgroup><tbody>
<tr valign="TOP"><td rowspan="15" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><span style="font-family: "Times New Roman", serif;"><strong>13-Stage Integer Pipeline</strong></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">0-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #999999;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">F#0</span></span></span></td><td colspan="10" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="684">用來產生要<span style="font-family: "Times New Roman", serif;">Fetch</span>指令的位址<span style="font-family: "Times New Roman", serif;">,</span>在文件中這個階段並不納入<span style="font-family: "Times New Roman", serif;">13</span>階的<span style="font-family: "Times New Roman", serif;">Pipeline</span>中<span style="font-family: "Times New Roman", serif;">. (AGC,Address Generator Unit)</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">1-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">F#1</span></span></span></td><td colspan="10" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="684"><span style="font-family: "Times New Roman", serif;">RAM+TLB ,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
支援兩個層級的全域歷史指令分支預測<span style="font-family: "Times New Roman", serif;">(Global History Branch Preditor)</span>分別為</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1,BTB(Branch Target Buffer)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
能用來判斷目前所要<span style="font-family: "Times New Roman", serif;">Fetch</span>的位址是否為分支<span style="font-family: "Times New Roman", serif;">(Branch)</span>指令<span style="font-family: "Times New Roman", serif;">,</span>以及所要調到的目標記憶體位址<span style="font-family: "Times New Roman", serif;">,</span>目前總共可以記錄<span style="font-family: "Times New Roman", serif;">512</span>筆資料<span style="font-family: "Times New Roman", serif;">,</span>若<span style="font-family: "Times New Roman", serif;">BTB</span>命中<span style="font-family: "Times New Roman", serif;">,</span>接下來就會進行<span style="font-family: "Times New Roman", serif;">GHB</span>的動作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2,GHB(Global History Buffer)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
包含<span style="font-family: "Times New Roman", serif;">4096</span>個<span style="font-family: "Times New Roman", serif;">2bits</span>計數器<span style="font-family: "Times New Roman", serif;">,</span>用來編碼分支預測的強度與方向<span style="font-family: "Times New Roman", serif;">,GHB</span>會以<span style="font-family: "Times New Roman", serif;">10bits</span>長度定址最近十筆分支的位址<span style="font-family: "Times New Roman", serif;">,</span>與<span style="font-family: "Times New Roman", serif;">4bits</span>的<span style="font-family: "Times New Roman", serif;">PC(Program Counter)</span>值<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此外<span style="font-family: "Times New Roman", serif;">,Return Stack(RS)</span>會記錄八筆<span style="font-family: "Times New Roman", serif;">32bits Link Register</span>的值<span style="font-family: "Times New Roman", serif;">,</span>當發現有關於函式返回<span style="font-family: "Times New Roman", serif;">(Return)</span>相關指令時<span style="font-family: "Times New Roman", serif;">,Return Stack</span>中所記錄的最近八筆<span style="font-family: "Times New Roman", serif;">Link Register</span>資訊就可以幫助<span style="font-family: "Times New Roman", serif;">Dynamic Branch Predictor</span>預測可能的分支結果<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">2-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">F#2</span></span></span></td><td colspan="10" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="684">提供<span style="font-family: "Times New Roman", serif;">12 </span>筆 <span style="font-family: "Times New Roman", serif;">Fetch Queue</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">3-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">D#0</span></span></span></td><td colspan="10" rowspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="684"><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;">Decode.</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">4-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">D#1</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">5-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">D#2</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">6-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">D#3</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">7-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">D#4</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">8-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">E#0</span></span></span></td><td colspan="10" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="684"><span style="font-family: "Times New Roman", serif;">Architectural Register File</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"></td><td bgcolor="#999999" colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="195"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><strong>ALU/MUL Pipeline 0</strong></span></span></span></td><td bgcolor="#999999" colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="169"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><strong>ALU Pipeline 1</strong></span></span></span></td><td bgcolor="#999999" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="300"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><strong>Load/Store Pipeline 0 or 1</strong></span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">9-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">E#1</span></span></span></td><td colspan="10" rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="684"><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;">Execution.</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">10-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">E#2</span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">11-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">E#3</span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">12-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">E#4</span></span></span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="195"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">BP Update(to F#0)</span></span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="169"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">BP Update(to F#0)</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="300"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">BP Update(to F#0)</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">13-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">E#5</span></span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="195"></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="169"></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="300"></td></tr>
<tr class="alt" valign="TOP"><td rowspan="12" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><span style="font-family: "Times New Roman", serif;">10-Stage NEON Pipeline</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"></td><td bgcolor="#999999" colspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="380"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>Instruction Decode</strong></span></span></td><td bgcolor="#999999" colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="294"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><strong>Load and Store with Alignment</strong></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">1-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">M#0</span></span></span></td><td colspan="7" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="380"><span style="font-family: "Times New Roman", serif;">16-entry NEON Instruction Queue/Instruction Decode</span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="294"><span style="font-family: "Times New Roman", serif;">Mux L1/MCR</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">2-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">M#1</span></span></span></td><td colspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="380"><span style="font-family: "Times New Roman", serif;">Decode Queue and Read/Write Check</span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="294"><span style="font-family: "Times New Roman", serif;">8-entry Load Queue</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">3-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">M#2</span></span></span></td><td colspan="7" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="380"><span style="font-family: "Times New Roman", serif;">Score-Board and Issue-Logic</span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="294"><span style="font-family: "Times New Roman", serif;">Load Align</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">4-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">M#3</span></span></span></td><td colspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="380"><span style="font-family: "Times New Roman", serif;">NEON Register Read and M3 fwding muxes</span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="294"><span style="font-family: "Times New Roman", serif;">Mux with NRF</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"></td><td bgcolor="#999999" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Integer ALU Pipe</strong></span></span></span></td><td bgcolor="#999999" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="86"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Integer MUL Pipe</strong></span></span></span></td><td bgcolor="#999999" colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Integer Shift Pipe</strong></span></span></span></td><td bgcolor="#999999" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="88"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>None-IEEE FP Add Pipe</strong></span></span></span></td><td bgcolor="#999999" colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="82"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>None-IEEE FP Mul Pipe</strong></span></span></span></td><td bgcolor="#999999" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>IEEE Single/Double precision VFP</strong></span></span></span></td><td bgcolor="#999999" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/Store and Permute Pipe</strong></span></span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">5-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N#1</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;">FMT</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="86"><span style="font-family: "Times New Roman", serif;">DUP</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;">SHIFT#1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="88"><span style="font-family: "Times New Roman", serif;">FFMT</span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="82"><span style="font-family: "Times New Roman", serif;">FDUP</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;">VFP</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">PERM#1</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">6-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N#2</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;">ALU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="86"><span style="font-family: "Times New Roman", serif;">MUL#1</span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;">SHIFT#2</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="88"><span style="font-family: "Times New Roman", serif;">FADD#1</span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="82"><span style="font-family: "Times New Roman", serif;">FMUL#1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;">Write Back</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">PERM#2</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">7-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N#3</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;">ABS</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="86"><span style="font-family: "Times New Roman", serif;">MUL#2</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"><span style="font-family: "Times New Roman", serif;">SHIFT#3</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="88"><span style="font-family: "Times New Roman", serif;">FADD#2</span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="82"><span style="font-family: "Times New Roman", serif;">FMUL#2</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">Store Align</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">8-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N#4</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="86"><span style="font-family: "Times New Roman", serif;">ACC#1</span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="88"><span style="font-family: "Times New Roman", serif;">FADD#3</span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="82"><span style="font-family: "Times New Roman", serif;">FMUL#3</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">8-entry Store Queue</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">9-Stage</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N#5</span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="86"><span style="font-family: "Times New Roman", serif;">ACC#2</span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="80"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="88"><span style="font-family: "Times New Roman", serif;">FADD#4</span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="82"><span style="font-family: "Times New Roman", serif;">FMUL#4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="77"><span style="font-family: "Times New Roman", serif;">10-Stage</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="color: #dc2300;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">N#6</span></span></span></td><td colspan="10" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="684"><span style="font-family: "Times New Roman", serif;">Write Back (Update to ARM/NEON Register File)</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Cortex A8</span>支援兩階的<span style="font-family: "Times New Roman", serif;">Cache,</span>其中<span style="font-family: "Times New Roman", serif;">L1 Cache</span>支援<span style="font-family: "Times New Roman", serif;">16kbytes</span>或<span style="font-family: "Times New Roman", serif;">32kbytes</span>的<span style="font-family: "Times New Roman", serif;">I/D-Cache(Harvard</span>架構<span style="font-family: "Times New Roman", serif;">),</span>與每個<span style="font-family: "Times New Roman", serif;">Byte</span>有一個<span style="font-family: "Times New Roman", serif;">Bit</span>的校正碼<span style="font-family: "Times New Roman", serif;">(Parity Bit),</span>每個<span style="font-family: "Times New Roman", serif;">Cache</span>都支援<span style="font-family: "Times New Roman", serif;">4ways</span>的機制<span style="font-family: "Times New Roman", serif;">(</span>可作為<span style="font-family: "Times New Roman", serif;">4</span>個快取區塊<span style="font-family: "Times New Roman", serif;">),</span>並使用<span style="font-family: "Times New Roman", serif;">Hash Virtual Address Buffer(HVAB)</span>預測<span style="font-family: "Times New Roman", serif;">Pipeline</span>要去<span style="font-family: "Times New Roman", serif;">L1 Cache</span>抓取的位置<span style="font-family: "Times New Roman", serif;">,</span>是在哪一個快取區塊<span style="font-family: "Times New Roman", serif;">,</span>可降低所需的時間與功耗<span style="font-family: "Times New Roman", serif;">,</span>並支援<span style="font-family: "Times New Roman", serif;">Write-Back</span>與<span style="font-family: "Times New Roman", serif;">Write-Through</span>相關機制<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">L2 Cache</span>支援<span style="font-family: "Times New Roman", serif;">64kbyes-2Mbytes</span>範圍的記憶體大小<span style="font-family: "Times New Roman", serif;">,</span>指令與資料都共用這一塊<span style="font-family: "Times New Roman", serif;">L2 Cache</span>空間<span style="font-family: "Times New Roman", serif;">,</span>提供<span style="font-family: "Times New Roman", serif;">L1 </span>與 <span style="font-family: "Times New Roman", serif;">L2 Cache</span>間高速的介面<span style="font-family: "Times New Roman", serif;">,</span>可用來避免處理器頻繁到外部<span style="font-family: "Times New Roman", serif;">AXI Bus</span>存取資料與和其他周邊搶資源<span style="font-family: "Times New Roman", serif;">,</span>所造成的效能影響<span style="font-family: "Times New Roman", serif;">,L2 Cache</span>支援<span style="font-family: "Times New Roman", serif;">8ways</span>的機制<span style="font-family: "Times New Roman", serif;">(</span>可作為<span style="font-family: "Times New Roman", serif;">8</span>個快取區塊<span style="font-family: "Times New Roman", serif;">),</span>可選擇支援<span style="font-family: "Times New Roman", serif;">ECC</span>與<span style="font-family: "Times New Roman", serif;">Parity Bit</span>校正碼<span style="font-family: "Times New Roman", serif;">,</span>並支援<span style="font-family: "Times New Roman", serif;">Write-Back,Write-Through</span>與<span style="font-family: "Times New Roman", serif;">Write-Allocate</span>機制<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM Cortex A8</span>是以<span style="font-family: "Times New Roman", serif;">Coprocessor</span>的架構支援新的<span style="font-family: "Times New Roman", serif;">NEON</span>多媒體指令集<span style="font-family: "Times New Roman", serif;">,ARM</span>對於<span style="font-family: "Times New Roman", serif;">Coprocessor</span>指令的辨別主要是在指令<span style="font-family: "Times New Roman", serif;">Decode</span>或<span style="font-family: "Times New Roman", serif;">Issue </span>時透過跟<span style="font-family: "Times New Roman", serif;">Coprocessor</span>判別是否為其支援的指令<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">NEON</span>多媒體指令的<span style="font-family: "Times New Roman", serif;">Pipeline</span>主要是介接在<span style="font-family: "Times New Roman", serif;">ARM</span>核心整數處理<span style="font-family: "Times New Roman", serif;">Pipeline</span>之後<span style="font-family: "Times New Roman", serif;">,</span>也因此所有的例外<span style="font-family: "Times New Roman", serif;">(Exception)</span>處理與分支<span style="font-family: "Times New Roman", serif;">Branch</span>預測問題在這之前都已經被處理好了<span style="font-family: "Times New Roman", serif;">,</span>此外<span style="font-family: "Times New Roman", serif;">,</span>有關對記憶體資料的<span style="font-family: "Times New Roman", serif;">Load/Store</span>動作<span style="font-family: "Times New Roman", serif;">,</span>也會在<span style="font-family: "Times New Roman", serif;">NEON Pipeline</span>之前<span style="font-family: "Times New Roman", serif;">,</span>就透過<span style="font-family: "Times New Roman", serif;">ARM</span>核心的<span style="font-family: "Times New Roman", serif;">Load/Store Pipeline</span>先從<span style="font-family: "Times New Roman", serif;">L1 D-Cache</span>執行完畢<span style="font-family: "Times New Roman", serif;">,</span>並儲存相關資料在<span style="font-family: "Times New Roman", serif;">NEON Pipeline</span>的<span style="font-family: "Times New Roman", serif;">Load/Store Data Queue</span>中<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">NEON</span>有自己的指令暫存空間<span style="font-family: "Times New Roman", serif;">(NEON Instruction Queue),</span>基於<span style="font-family: "Times New Roman", serif;">ARM</span>的<span style="font-family: "Times New Roman", serif;">Dual-Issue</span>架構<span style="font-family: "Times New Roman", serif;">,</span>每次處理器週期<span style="font-family: "Times New Roman", serif;">,</span>最多可以指派兩個有效的<span style="font-family: "Times New Roman", serif;">NEON</span>指令集<span style="font-family: "Times New Roman", serif;">,NEON</span>的指令集可以一次從<span style="font-family: "Times New Roman", serif;">L1</span>或<span style="font-family: "Times New Roman", serif;">L2 Cache</span>中<span style="font-family: "Times New Roman", serif;">Load/Store 128bits</span>的資料<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">NEON</span>有三個整數<span style="font-family: "Times New Roman", serif;">SIMD Pipelines(</span>包含整數乘法累加<span style="font-family: "Times New Roman", serif;">Pipeline,</span>整數<span style="font-family: "Times New Roman", serif;">Shift Pipeline</span>與整數邏輯運算<span style="font-family: "Times New Roman", serif;">Pipeline),</span>一個<span style="font-family: "Times New Roman", serif;">Load-Store/Permute Pipeline(</span>負責<span style="font-family: "Times New Roman", serif;">NEON</span>資料的<span style="font-family: "Times New Roman", serif;">Load/Store</span>與資料存取整數單元<span style="font-family: "Times New Roman", serif;">Integer Unit),</span>兩個<span style="font-family: "Times New Roman", serif;">SIMD single-precision floating-point Pipelines(</span>分別負責浮點數的乘法與加法<span style="font-family: "Times New Roman", serif;">)</span>與一個<span style="font-family: "Times New Roman", serif;">Non-Pipelined Vector Floating-Point Unit(VFPLite,</span>遵循<span style="font-family: "Times New Roman", serif;">ARM VFPv3</span>浮點數規格<span style="font-family: "Times New Roman", serif;">,</span>並符合<span style="font-family: "Times New Roman", serif;">IEEE754</span>關於浮點數的規範<span style="font-family: "Times New Roman", serif;">,</span>並向後相容原本<span style="font-family: "Times New Roman", serif;">ARM</span>的浮點數實作<span style="font-family: "Times New Roman", serif;">). NEON</span>指令在<span style="font-family: "Times New Roman", serif;">Pipeline</span>中是以<span style="font-family: "Times New Roman", serif;">in-order</span>方式被執行<span style="font-family: "Times New Roman", serif;">,</span>所處理的資料要不就是<span style="font-family: "Times New Roman", serif;">NEON</span>整數<span style="font-family: "Times New Roman", serif;">SIMD</span>指令就是<span style="font-family: "Times New Roman", serif;">NEON</span>浮點運算指令<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而隨著處理器時脈的提升<span style="font-family: "Times New Roman", serif;">,</span>每一個處理器<span style="font-family: "Times New Roman", serif;">Cycle,</span>每一階的 <span style="font-family: "Times New Roman", serif;">Pipeline</span>所能做的事情也越加精簡<span style="font-family: "Times New Roman", serif;">(</span>每一個<span style="font-family: "Times New Roman", serif;">Cycle</span>執行的時間相對也越短<span style="font-family: "Times New Roman", serif;">),</span>伴隨著就是<span style="font-family: "Times New Roman", serif;">Pipeline</span>階數的增加<span style="font-family: "Times New Roman", serif;">,</span>只要<span style="font-family: "Times New Roman", serif;">Branch Predition</span>的準確度高<span style="font-family: "Times New Roman", serif;">,Pipeline</span>被<span style="font-family: "Times New Roman", serif;">Flush</span>的機率低<span style="font-family: "Times New Roman", serif;">,</span>就能透過<span style="font-family: "Times New Roman", serif;">Pipeline</span>階數增加得到處理器時脈提升的效能好處<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>指令集在每個指令都有<span style="font-family: "Times New Roman", serif;">4bits</span>的<span style="font-family: "Times New Roman", serif;">Condition,</span>對於<span style="font-family: "Times New Roman", serif;">Pipeline</span>的架構來說<span style="font-family: "Times New Roman", serif;">,</span>可以直接判斷<span style="font-family: "Times New Roman", serif;">PSR(Program Ststu Register)</span>決定該指令該如何執行的條件<span style="font-family: "Times New Roman", serif;">,</span>優化效能<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>的處理器核心命名也有一個可識別性<span style="font-family: "Times New Roman", serif;">,</span>例如<span style="font-family: "Times New Roman", serif;">:ARM7-TDMI (ARM7-Thumb+Debug+Multiplier+ICE),</span>指的就是這個<span style="font-family: "Times New Roman", serif;">ARM7-TDMI</span>的核心<span style="font-family: "Times New Roman", serif;">,</span>支援<span style="font-family: "Times New Roman", serif;">16bits Thumb Code,</span>晶片除錯<span style="font-family: "Times New Roman", serif;">JTAG (IEEE 1149.1 ),</span>硬體乘法器(<span style="font-family: "Times New Roman", serif;">Multiplier</span>)與<span style="font-family: "Times New Roman", serif;">ICE</span>-<span style="font-family: "Times New Roman", serif;">RT</span>嵌入式邏輯<span style="font-family: "Times New Roman", serif;">/</span>追蹤巨集單元<span style="font-family: "Times New Roman", serif;">.</span>或像是<span style="font-family: "Times New Roman", serif;">J</span>為支援<span style="font-family: "Times New Roman", serif;">Jazelle</span>指令集與<span style="font-family: "Times New Roman", serif;">F</span>為支援向量浮點數<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡單介紹一下<span style="font-family: "Times New Roman", serif;">,ARM </span>最新<span style="font-family: "Times New Roman", serif;">Cortex</span>系列的處理器<span style="font-family: "Times New Roman", serif;">,</span>從早期的<span style="font-family: "Times New Roman", serif;">ARM7(armv4),ARM9(armv5),ARM11(armv6)</span>到現在的<span style="font-family: "Times New Roman", serif;">Cortex(armv7)</span>架構<span style="font-family: "Times New Roman", serif;">,</span>每一個世代都有包括新的指令集<span style="font-family: "Times New Roman", serif;"><span style="text-decoration-line: underline;"><strong>(</strong></span></span><span style="text-decoration-line: underline;"><strong>例如</strong><span style="font-family: "Times New Roman", serif;"><strong>:v4T</strong></span></span><span style="text-decoration-line: underline;"><strong>導入</strong><span style="font-family: "Times New Roman", serif;"><strong>Thumb</strong></span></span><span style="text-decoration-line: underline;"><strong>指令集</strong><span style="font-family: "Times New Roman", serif;"><strong>,v5E</strong></span></span><span style="text-decoration-line: underline;"><strong>導入增強型</strong><span style="font-family: "Times New Roman", serif;"><strong>DSP</strong></span></span><span style="text-decoration-line: underline;"><strong>指令</strong><span style="font-family: "Times New Roman", serif;"><strong>,v6</strong></span></span><span style="text-decoration-line: underline;"><strong>新增</strong><span style="font-family: "Times New Roman", serif;"><strong>Thumb2</strong></span></span><span style="text-decoration-line: underline;"><strong>與</strong><span style="font-family: "Times New Roman", serif;"><strong>SIMD</strong></span></span><span style="text-decoration-line: underline;"><strong>指令集</strong><span style="font-family: "Times New Roman", serif;"><strong>)</strong></span></span><span style="font-family: "Times New Roman", serif;">,</span>架構與效能上的諸多改善<span style="font-family: "Times New Roman", serif;">,</span>而到了<span style="font-family: "Times New Roman", serif;">Cortex</span>時<span style="font-family: "Times New Roman", serif;">,ARM</span>第一次同時推出三個等級的產品線<span style="font-family: "Times New Roman", serif;">,</span>主要說明如下</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 898px;"><colgroup><col width="140"></col><col width="736"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="140"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex A(Application)</span></span><span style="font-size: xx-small;">系列</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="736">主要用於高性能的開放平台<span style="font-family: "Times New Roman", serif;">,</span>一般而言也都具備<span style="font-family: "Times New Roman", serif;">MMU,</span>例如<span style="font-family: "Times New Roman", serif;">Symbian,Linux/Android</span>或是<span style="font-family: "Times New Roman", serif;">Windows Mobile/Phone.</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="140"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex R(Real-Time)</span></span><span style="font-size: xx-small;">系列</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="736">用於高端的嵌入式系統產品<span style="font-family: "Times New Roman", serif;">,</span>例如汽車電子組件<span style="font-family: "Times New Roman", serif;">,</span>機械手臂這類要求處理器功能強大<span style="font-family: "Times New Roman", serif;">,</span>高可靠度與對事件反應快速的應用<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="140"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex M<br />(</span><span style="font-size: xx-small;">M</span><span style="font-size: xx-small;">icrocontroller)</span></span><span style="font-size: xx-small;">系列</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="736">用於嵌入式與單晶片的產品<span style="font-family: "Times New Roman", serif;">,</span>針對過去<span style="font-family: "Times New Roman", serif;">8051</span>這類單晶片所在的<span style="font-family: "Times New Roman", serif;">Real-Time,</span>低功耗與成本的應用<span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前台灣的新唐也推出<span style="font-family: "Times New Roman", serif;">Cortex-M0</span>低價處理器<span style="font-family: "Times New Roman", serif;">(mmm…</span>我理解是在<span style="font-family: "Times New Roman", serif;">1USD</span>以下<span style="font-family: "Times New Roman", serif;">),</span>或像是<span style="font-family: "Times New Roman", serif;">Cortex-M3</span>只支援部分常用<span style="font-family: "Times New Roman", serif;">Thumb2</span>指令集<span style="font-family: "Times New Roman", serif;">(</span>不支援<span style="font-family: "Times New Roman", serif;">ARM</span>指令集<span style="font-family: "Times New Roman", serif;">)</span>與中斷向量表<span style="font-family: "Times New Roman", serif;">,</span>藉此提供高密度與效能的執行環境<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: xx-small;"><br /></span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以下根據<span style="font-family: "Times New Roman", serif;">ARM</span>系列的差異<span style="font-family: "Times New Roman", serif;">,</span>逐一說明</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(</span>參考網站 <span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/ARM_architecture" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/ARM_architecture</a></span></span>)</span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 988px;"><colgroup><col width="70"></col><col width="71"></col><col width="101"></col><col width="221"></col><col width="56"></col><col width="71"></col><col width="116"></col><col width="248"></col></colgroup><tbody>
<tr valign="TOP"><td height="55" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM Family</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">ARM Core</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">ARM Architecture</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;">Features</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">Cache<br />(I/D)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU/<br />MPU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;">Performance</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">Applied<br />Product</span></td></tr>
<tr class="alt" valign="TOP"><td height="23" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">ARM Evaluation System second processor for BBC Micro</span></td></tr>
<tr class="" valign="TOP"><td height="24" rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM2</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv2 added the MUL (multiply) instruction</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">4 MIPS @ 8 MHz</span><span style="font-size: xx-small;"><br /></span><span style="font-size: xx-small;">0.33 </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/DMIPS" style="color: #666666; font-weight: bold; text-decoration-line: none;">DMIPS</a></span></span><span style="font-size: xx-small;">/MHz</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">Acorn Archimedes, Chessmachine</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv2a</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM250</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Integrated MEMC (MMU), Graphics and IO processor. ARMv2a added the SWP and SWPB (swap) instructions.</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MEMC1a</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">7 MIPS @ 12 MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">Acorn Archimedes</span></td></tr>
<tr valign="TOP"><td height="21" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM3</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv2a</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM3</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">First integrated memory cache.</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">4 KB unified</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">12 MIPS @ 25 MHz</span><span style="font-size: xx-small;"><br /></span><span style="font-size: xx-small;">0.50 DMIPS/MHz</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">Acorn Archimedes</span></td></tr>
<tr class="alt" valign="TOP"><td height="21" rowspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM6</span></td><td rowspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv3</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM60</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv3 first to support 32-bit memory address space (previously 26-bit)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">10 MIPS @ 12 MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">3DO Interactive Multiplayer, Zarlink GPS Receiver</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM600</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM60, cache and coprocessor bus (for FPA10 floating-point unit).</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">4 KB unified</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">28 MIPS @ 33 MHz</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM610</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM60, cache, no coprocessor bus.</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">4 KB unified</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">17 MIPS @ 20 MHz</span><span style="font-size: xx-small;"><br /></span><span style="font-size: xx-small;">0.65 DMIPS/MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">Acorn Risc PC 600, Apple Newton 100 series</span></td></tr>
<tr valign="TOP"><td height="19" rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM7</span></td><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv3</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM700</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8 </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Kilobyte" style="color: #666666; font-weight: bold; text-decoration-line: none;">KB</a></span></span><span style="font-size: xx-small;"></span><span style="font-size: xx-small;">unified</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Risc_PC" style="color: #666666; font-weight: bold; text-decoration-line: none;">Acorn Risc PC</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">prototype CPU card</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM710</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM700, no coprocessor bus.</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8 </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Kilobyte" style="color: #666666; font-weight: bold; text-decoration-line: none;">KB</a></span></span><span style="font-size: xx-small;"></span><span style="font-size: xx-small;">unified</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Risc_PC" style="color: #666666; font-weight: bold; text-decoration-line: none;">Acorn Risc PC 700</a></span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM710a</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM710</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8 </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Kilobyte" style="color: #666666; font-weight: bold; text-decoration-line: none;">KB</a></span></span><span style="font-size: xx-small;"></span><span style="font-size: xx-small;">unified</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">40 MHz</span><span style="font-size: xx-small;"><br /></span><span style="font-size: xx-small;">0.68 DMIPS/MHz</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Risc_PC" style="color: #666666; font-weight: bold; text-decoration-line: none;">Acorn Risc PC 700</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/EMate_300" style="color: #666666; font-weight: bold; text-decoration-line: none;">Apple eMate 300</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Psion_5" style="color: #666666; font-weight: bold; text-decoration-line: none;">Psion Series 5</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">(ARM7100),</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Acorn_A7000" style="color: #666666; font-weight: bold; text-decoration-line: none;">Acorn A7000</a></span></span><span style="font-size: xx-small;">(ARM7500),</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Acorn_A7000" style="color: #666666; font-weight: bold; text-decoration-line: none;">Acorn A7000+</a></span></span><span style="font-size: xx-small;"></span><span style="font-size: xx-small;">(ARM7500FE),</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Acorn_Network_Computer" style="color: #666666; font-weight: bold; text-decoration-line: none;">Network Computer</a></span></span><span style="font-size: xx-small;"></span><span style="font-size: xx-small;">(ARM7500FE)</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="22" rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM7TDMI</span></td><td rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv4T</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM7TDMI(-S)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">3-stage pipeline, Thumb</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">15 MIPS @ 16.8 MHz</span><span style="font-size: xx-small;"><br /></span><span style="font-size: xx-small;">63 DMIPS @ 70 MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Game_Boy_Advance" style="color: #666666; font-weight: bold; text-decoration-line: none;">Game Boy Advance</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Nintendo_DS" style="color: #666666; font-weight: bold; text-decoration-line: none;">Nintendo DS</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/IPod" style="color: #666666; font-weight: bold; text-decoration-line: none;">Apple iPod</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Lego_NXT" style="color: #666666; font-weight: bold; text-decoration-line: none;">Lego NXT</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Juice_Box" style="color: #666666; font-weight: bold; text-decoration-line: none;">Juice Box</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Garmin" style="color: #666666; font-weight: bold; text-decoration-line: none;">Garmin</a></span></span><span style="font-size: xx-small;">Navigation Devices (1990s – early 2000s)</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">ARM710T</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM7TDMI, cache</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8 KB unified</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">36 MIPS @ 40 MHz</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">Psion Series 5mx, Psion Revo/Revo Plus/Diamond Mako</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM720T</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM7TDMI, cache, MMU with Fast Context Switch Extension</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8 KB unified</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">60 MIPS @ 59.8 MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Zipit_Wireless_Messenger" style="color: #666666; font-weight: bold; text-decoration-line: none;">Zipit Wireless Messenger</a></span></span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM740T</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM7TDMI, cache</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8 KB unified</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">MPU</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td height="35" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM7EJ</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv5TEJ</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM7EJ-S</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">5-stage pipeline, Thumb, Jazelle DBX, Enhanced DSP instructions</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr valign="TOP"><td height="12" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM8</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv4</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM810</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">5-stage pipeline, static branch prediction, double-bandwidth memory</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8 KB unified</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">84 MIPS @ 72 MHz</span><span style="font-size: xx-small;"><br /></span><span style="font-size: xx-small;">1.16 DMIPS/MHz</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Risc_PC" style="color: #666666; font-weight: bold; text-decoration-line: none;">Acorn Risc PC</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">prototype CPU card</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">StrongARM</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv4</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SA-1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">5-stage pipeline</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">16 KB/8–16 KB</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">MMU</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">203–206 MHz</span><span style="font-size: xx-small;"><br /></span><span style="font-size: xx-small;">1.0 DMIPS/MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">SA-110</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Apple Newton 2×00 series, Acorn Risc PC, Rebel/Corel Netwinder, Chalice CATS</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">SA-1100</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Psion netBook</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">SA-1110</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">LART (computer), Intel Assabet, Ipaq H36x0, Balloon2, Zaurus SL-5×00, HP Jornada 7xx, Jornada 560 series, Palm Zire 31</span></div>
</td></tr>
<tr valign="TOP"><td height="17" rowspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM9TDMI</span></td><td rowspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv4T</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM9TDMI</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">5-stage pipeline, Thumb</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">None</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM920T</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM9TDMI, cache, MMU with FCSE (Fast Context Switch Extension)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">16 KB/16 KB</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">MMU</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">200 MIPS @ 180 MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/w/index.php?title=Armadillo_CPU_Boards&action=edit&redlink=1" style="color: #666666; font-weight: bold; text-decoration-line: none;">Armadillo</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/GP32" style="color: #666666; font-weight: bold; text-decoration-line: none;">GP32</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/GP2X" style="color: #666666; font-weight: bold; text-decoration-line: none;">GP2X</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">(first core),</span><span style="font-size: xx-small;"></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Tapwave_Zodiac" style="color: #666666; font-weight: bold; text-decoration-line: none;">Tapwave Zodiac</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">(</span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Motorola" style="color: #666666; font-weight: bold; text-decoration-line: none;">Motorola</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">i.MX1), Hewlett-Packard</span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/HP-49_series" style="color: #666666; font-weight: bold; text-decoration-line: none;">HP-49/50 Calculators</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Sun_SPOT" style="color: #666666; font-weight: bold; text-decoration-line: none;">Sun SPOT</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/HTC_TyTN" style="color: #666666; font-weight: bold; text-decoration-line: none;">HTC TyTN</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/First_International_Computer" style="color: #666666; font-weight: bold; text-decoration-line: none;">FIC</a></span></span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Neo_FreeRunner" style="color: #666666; font-weight: bold; text-decoration-line: none;">Neo FreeRunner</a></span></span><span style="font-size: xx-small;">),</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Garmin" style="color: #666666; font-weight: bold; text-decoration-line: none;">Garmin</a></span></span><span style="font-size: xx-small;">Navigation Devices (mid–late 2000s),</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/TomTom" style="color: #666666; font-weight: bold; text-decoration-line: none;">TomTom</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">navigation devices</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM922T</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM9TDMI, caches</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">8 KB/8 KB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM940T</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM9TDMI, caches</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">4 KB/4 KB</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MPU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/GP2X" style="color: #666666; font-weight: bold; text-decoration-line: none;">GP2X</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">(second core), Meizu</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/M6_Mini_Player" style="color: #666666; font-weight: bold; text-decoration-line: none;">M6 Mini Player</a></span></span></span></td></tr>
<tr valign="TOP"><td height="14" rowspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM9E</span></td><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv5TE</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM946E-S</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Thumb, Enhanced DSP instructions, caches, TCM (tightly coupled memories)</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MPU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Nintendo_DS" style="color: #666666; font-weight: bold; text-decoration-line: none;">Nintendo DS</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Nokia" style="color: #666666; font-weight: bold; text-decoration-line: none;">Nokia</a></span></span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/N-Gage" style="color: #666666; font-weight: bold; text-decoration-line: none;">N-Gage</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Canon_PowerShot_A470" style="color: #666666; font-weight: bold; text-decoration-line: none;">Canon PowerShot A470</a></span></span><span style="font-size: xx-small;">,</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Canon_EOS_5D_Mark_II" style="color: #666666; font-weight: bold; text-decoration-line: none;">Canon EOS 5D Mark II</a></span></span><span style="font-size: xx-small;"> ,Conexant 802.11 chips, Samsung S5L2010</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM966E-S</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;">T<span style="font-size: xx-small;">humb, Enhanced DSP instructions, TCM (tightly coupled memories)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM968E-S</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM966E-S</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv5TEJ</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM926EJ-S</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Thumb, Jazelle DBX, Enhanced DSP instructions, caches, TCM (tightly coupled memories)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">220 MIPS @ 200 MHz,</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Mobile phones:</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Sony_Ericsson" style="color: #666666; font-weight: bold; text-decoration-line: none;">Sony Ericsson</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">(K, W series);</span><span style="font-size: xx-small;"></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Siemens_AG" style="color: #666666; font-weight: bold; text-decoration-line: none;">Siemens</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">and</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Benq" style="color: #666666; font-weight: bold; text-decoration-line: none;">Benq</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">(x65 series and newer);</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/LG_KM900_(Arena)" style="color: #666666; font-weight: bold; text-decoration-line: none;">LG Arena</a></span></span><span style="font-size: xx-small;">; GPH Wiz;</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Squeezebox_(network_music_player)#Squeezebox_Duet_.28January_2008.29" style="color: #666666; font-weight: bold; text-decoration-line: none;">Squeezebox Duet</a></span></span><span style="font-size: xx-small;"></span><span style="font-size: xx-small;">Controller (Samsung S3C2412).</span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Squeezebox_(network_music_player)#Squeezebox_Radio_.28September_2009.29" style="color: #666666; font-weight: bold; text-decoration-line: none;">Squeezebox Radio</a></span></span><span style="font-size: xx-small;">;</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Buffalo_network-attached_storage_series" style="color: #666666; font-weight: bold; text-decoration-line: none;">Buffalo</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">TeraStation Live (</span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Network-attached_storage" style="color: #666666; font-weight: bold; text-decoration-line: none;">NAS</a></span></span><span style="font-size: xx-small;">);</span><span style="font-size: xx-small;"></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Drobo" style="color: #666666; font-weight: bold; text-decoration-line: none;">Drobo FS</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">(</span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Network-attached_storage" style="color: #666666; font-weight: bold; text-decoration-line: none;">NAS</a></span></span><span style="font-size: xx-small;">); Western Digital MyBook I World Edition; Western Digital MyBook II World Edition;</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Seagate_FreeAgent" style="color: #666666; font-weight: bold; text-decoration-line: none;">Seagate FreeAgent</a><a href="http://www.seagate.com/www/en-us/products/network_storage/freeagent_dockstar/" style="color: #666666; font-weight: bold; text-decoration-line: none;">DockStar</a></span></span><span style="font-size: xx-small;"></span><span style="font-size: xx-small;">STDSD10G-RK;</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Seagate_FreeAgent" style="color: #666666; font-weight: bold; text-decoration-line: none;">Seagate FreeAgent</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">GoFlex Home;</span><span style="font-size: xx-small;"> </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/Chumby" style="color: #666666; font-weight: bold; text-decoration-line: none;">Chumby</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">Classic</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv5TE</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM996HS</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="color: red;"><span style="font-size: xx-small;">Clockless</span></span><span style="font-size: xx-small;"> processor, as ARM966E-S, TCM (tightly coupled memories)</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MPU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td height="24" rowspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM10E</span></td><td rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv5TE</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM1020E</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">6-stage pipeline, Thumb, Enhanced DSP instructions, (VFP)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">32 KB/32 KB</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM1022E</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM1020E</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">16 KB/16 KB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv5TEJ</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM1026EJ-S</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Thumb, Jazelle DBX, Enhanced DSP instructions, (VFP)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU or MPU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="" valign="TOP"><td height="21" rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">XScale</span></td><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv5TE</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">XScale</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">7-stage pipeline, Thumb, Enhanced DSP instructions</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">32 KB/32 KB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">133–400 MHz</span></span></td><td rowspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">80219</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Thecus N2100</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">IOP321</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Iyonix</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PXA210/PXA250</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Zaurus SL-5600, iPAQ H3900, Sony CLIE NX60, NX70V, NZ90</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PXA255</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Gumstix basix & connex, Palm Tungsten E2, Zaurus SL-C860, Mentor Ranger & Stryder, iRex ILiad</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PXA263</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Sony CLIE NX73V, NX80V</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PXA26x</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Palm Tungsten T3</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PXA27x</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Gumstix verdex, “Trizeps-Modules”, “eSOM270-Module” PXA270 COM, HTC Universal, HP hx4700, Zaurus SL-C1000, 3000, 3100, 3200, Dell Axim x30, x50, and x51 series, Motorola Q, Balloon3, Trolltech Greenphone, Palm TX, Motorola Ezx Platform A728, A780, A910, A1200, E680, E680i, E680g, E690, E895, Rokr E2, Rokr E6, Fujitsu Siemens LOOX N560, Toshiba Portege G500, Tr?o 650-755p, Zipit Z2, HP iPaq 614c Business Navigator, I-mate PDA2</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PXA3XX</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Samsung Omnia</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PXA900</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Blackberry 8700, Blackberry Pearl (8100)</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">IXP42x</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">NSLU2</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">Bulverde</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;">Wireless MMX, Wireless SpeedStep added</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">32 KB/32 KB</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">312–624 MHz</span></span></td></tr>
<tr class="" valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">Monahans</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Wireless MMX2 added, 32 KB/32 KB (L1), optional L2 cache up to 512 KB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">32 KB/32 KB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">up to 1.25 GHz</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="19" rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">ARM11</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv6</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM1136J(F)-S</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;">8-stage pipeline, SIMD, Thumb, Jazelle DBX, (VFP), Enhanced DSP instructions</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">OMAP2420</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Nokia E90, Nokia N93, Nokia N95, Nokia N82, Zune, BUGbase, Nokia N800, Nokia N810</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MSM7200</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Eten Glofiish, HTC TyTN II, HTC Nike</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Freescale i.MX31</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">original Zune 30?GB, Toshiba Gigabeat S and Kindle DX</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Freescale MXC300-30</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Nokia E63, Nokia E71, Nokia 5800, Nokia E51, Nokia 6700 Classic, Nokia 6120 Classic, Nokia 6210 Navigator, Nokia 6220 Classic, Nokia 6290, Nokia 6710 Navigator, Nokia 6720 Classic, Nokia E75, Nokia N97, Nokia N81</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Qualcomm MSM7201A</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">HTC Dream, HTC Magic, Motorola i1, Motorola Z6, HTC Hero, Samsung SGH-i627 (Propel Pro), Sony Ericsson Xperia X10 Mini Pro</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Qualcomm MSM7227</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ZTE Link, HTC Legend, HTC Aria, Viewsonic ViewPad 7</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv6T2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM1156T2(F)-S</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;">9-stage pipeline, SIMD, Thumb-2, (VFP), Enhanced DSP instructions</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MPU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv6ZK</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM1176JZ(F)-S</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM1136EJ(F)-S, TrustZone</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;">965?DMIPS @ 772?MHz</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">up to 2600DMIPS with four processors</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">Apple iPhone (original and 3G), Apple iPod touch (1st and 2nd Generation), Motorola RIZR Z8, Motorola RIZR Z10, Nintendo 3DS</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">S3C6410</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Samsung Omnia II, Samsung Moment, SmartQ 5, Tablet PC</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Qualcomm MSM7627</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Palm Pixi and Motorola Calgary/Devour</span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv6K</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARM11 MPCore</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">As ARM1136EJ(F)-S, 1–4 core SMP</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td height="30" rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">Cortex-A</span></td><td rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv7-A</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex-A5</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">VFP, NEON, Jazelle RCT, Thumb/Thumb-2, 1–4 cores,Variable (L1 + L2) Cache, MMU + TrustZone</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1.57 DMIPS / MHz per core</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">Cortex-A8</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;">VFP, NEON, Jazelle RCT, Thumb-2, 13-stage superscalar pipeline,<span style="font-size: xx-small;"> Variable (L1 + L2) Cache, MMU + TrustZone</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">up to 2 000 (2.0 DMIPS/MHz in speed from 600 MHz to greater than 1 GHz)</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">HTC Desire, SBM7000, Oregon State University OSWALD, Gumstix Overo Earth, Pandora, Apple iPhone 3GS, Apple iPod touch (3rd and 4th Generation), Apple iPad (A4), Apple iPhone 4 (A4), Archos 5, BeagleBoard, Motorola Droid, Motorola Droid X, Motorola Droid 2, Motorola Droid R2D2 Edition, Palm Pre, Samsung Omnia HD, Samsung Wave S8500, Samsung i9000 Galaxy S, Sony Ericsson Satio, Touch Book, Nokia N900, Meizu M9, Google Nexus S, Sharp PC-Z1 “Netwalker”.</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">Cortex-A9 MPCore</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;">Application profile, VFPv3 FPU, NEON, Thumb-2, Jazelle RCT/DBX, out-of-order speculative issue superscalar, 1–4 core SMP,</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">32 KB/32 KB L1, up to 4 MB L2, MMU + TrustZone</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">2.5 DMIPS/MHz per core, 10 000 DMIPS @ 2 GHz on Performance Optimized TSMC</span><span style="font-size: xx-small;"></span><span style="font-size: xx-small;">40G(dual core)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"><span style="font-family: "Times New Roman", serif;">LG Optimus 2X, Motorola Atrix 4G,Motorola DROID BIONIC, Motorola Xoom Pandaboard</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;">Cortex-A15 MPCore</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Application profile, VFPv4 FPU, NEON, Thumb-2, Jazelle RCT/DBX, out-of-order speculative issue superscalar, Large Physical Address Extensions (LPAE), Hardware virtualization, 1–4 SMP cores,</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">32 KB/32 KB L1, up to 4 MB L2, MMU + TrustZone</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MMU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td height="10" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">Cortex-R</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv7-R</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex-R4(F)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Real-time profile, Thumb-2, (FPU), variable cache, MPU optional</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Variable</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MPU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">600 </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://en.wikipedia.org/wiki/DMIPS" style="color: #666666; font-weight: bold; text-decoration-line: none;">DMIPS</a></span></span><span style="font-size: xx-small;"> </span><span style="font-size: xx-small;">@ 475 MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr valign="TOP"><td height="21" rowspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="70"><span style="font-family: "Times New Roman", serif;">Cortex-M</span></td><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv6-M</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex-M0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Microcontroller profile, Thumb-2 subset (16-bit Thumb instructions & BL, MRS, MSR, ISB, DSB, and DMB). Hardware multiply instruction optional</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0.9 DMIPS/MHz</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex-M1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">FPGA targeted, Microcontroller profile, Thumb-2 subset (16-bit Thumb instructions & BL, MRS, MSR, ISB, DSB, and DMB),TCM(tightly coupled memory)optional.</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Up to 136 DMIPS @ 170 MHz (0.8 DMIPS/MHz, MHz achievable FPGA-dependent)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv7-M</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex-M3</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Microcontroller profile, Thumb-2 only. Hardware divide instruction, no cache, MPU optional.</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MPU</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1.25 DMIPS/MHz</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ARMv7-ME</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Cortex-M4</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="221"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Microcontroller profile, both Thumb and Thumb-2, FPU. Hardware MAC, SIMD and divide instructions, MPU optional</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;">None</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="71"><span style="font-family: "Times New Roman", serif;">MPU</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="116"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1.25 DMIPS/MHz</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="248"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>簡要說明</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>ARM</strong></span></span><span style="font-size: small;"><strong>的架構如下</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>處理器起始位址一般是<span style="font-family: "Times New Roman", serif;">0x00000000,</span>初始化時是處於<span style="font-family: "Times New Roman", serif;">SVC(Supervisor) Mode,</span>並可以透過<span style="font-family: "Times New Roman", serif;">System Coprocessor</span>設定為<span style="font-family: "Times New Roman", serif;">Little Endian(</span>高位址資料較小<span style="font-family: "Times New Roman", serif;">)</span>或<span style="font-family: "Times New Roman", serif;">Bigger Endian(</span>高位址資料較大<span style="font-family: "Times New Roman", serif;">),ARM</span>的<span style="font-family: "Times New Roman", serif;">I/O</span>對應的方式為<span style="font-family: "Times New Roman", serif;">Memory Mapped I/O (X86</span>為<span style="font-family: "Times New Roman", serif;">I/O Mapped I/O,</span>要透過 <span style="font-family: "Times New Roman", serif;">in/out</span>指令才可以存取<span style="font-family: "Times New Roman", serif;">I/O Space).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>支援八類處理器執行模式<span style="font-family: "Times New Roman", serif;">,</span>如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(</span>參考<span style="font-family: "Times New Roman", serif;">:ARMv7-AR Architecture Reference Manual)</span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 920px;"><colgroup><col width="155"></col><col width="119"></col><col width="168"></col><col width="461"></col></colgroup><tbody>
<tr valign="TOP"><td height="24" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155">處理器模式</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">xPSR Mode encoding</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Priviledge</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">說明</td></tr>
<tr class="alt" valign="TOP"><td height="25" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155"><span style="font-family: "Times New Roman", serif;">USR</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">b10000</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Unpriviledged</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">使用者模式<span style="font-family: "Times New Roman", serif;"><br /></span>例如<span style="font-family: "Times New Roman", serif;">,</span>我們在<span style="font-family: "Times New Roman", serif;">ARM Linux</span>上的應用程式<span style="font-family: "Times New Roman", serif;">,</span>就是處於這個模式<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr valign="TOP"><td height="9" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155"><span style="font-family: "Times New Roman", serif;">FIQ</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">b10001</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Priviledged</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">快速中斷模式</td></tr>
<tr class="alt" valign="TOP"><td height="23" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155"><span style="font-family: "Times New Roman", serif;">IRQ</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">b10010</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Priviledged</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">通用中斷處理</td></tr>
<tr valign="TOP"><td height="7" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155"><span style="font-family: "Times New Roman", serif;">SVC (Supervisor)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">b10011</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Priviledged</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">管理者保護模式<span style="font-family: "Times New Roman", serif;">,</span>一般沒有區分特權等級的<span style="font-family: "Times New Roman", serif;">RTOS,</span>或是有區分特權等級的<span style="font-family: "Times New Roman", serif;">OS Kernel Mode</span>都會處於這個模式<span style="font-family: "Times New Roman", serif;">. </span>包括<span style="font-family: "Times New Roman", serif;">,</span>使用者透過<span style="font-family: "Times New Roman", serif;">SWI(or SVC)</span>觸發軟體中斷 <span style="font-family: "Times New Roman", serif;">(</span>對應到一般<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>就是用<span style="font-family: "Times New Roman", serif;">SWI</span>實現<span style="font-family: "Times New Roman", serif;">System Call),</span>也會進入到<span style="font-family: "Times New Roman", serif;">SVC Mode.</span></td></tr>
<tr class="alt" valign="TOP"><td height="21" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155"><span style="font-family: "Times New Roman", serif;">MON(Monitor)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">b10110</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Priviledged</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">只有當處理器支援<span style="font-family: "Times New Roman", serif;">Security Extensions</span>時<span style="font-family: "Times New Roman", serif;">,</span>才會有這模式<span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以透過<span style="font-family: "Times New Roman", serif;">SMC(Secure Monitor Call)</span>指令<span style="font-family: "Times New Roman", serif;">,</span>讓系統進入<span style="font-family: "Times New Roman", serif;">Secure Mode,</span>或可透過設定<span style="font-family: "Times New Roman", serif;">Secure Configuration Register,</span>讓系統所觸發的<span style="font-family: "Times New Roman", serif;">IRQ/FIQ/Abort</span>都變成進入<span style="font-family: "Times New Roman", serif;">Secure Mode</span>中處理<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr valign="TOP"><td height="21" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155"><span style="font-family: "Times New Roman", serif;">ABT (Abort)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">b10111</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Priviledged</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">記憶體存取異常模式 <span style="font-family: "Times New Roman", serif;">(</span>發生<span style="font-family: "Times New Roman", serif;">Data</span>或是<span style="font-family: "Times New Roman", serif;">Prefetch Abort</span>時<span style="font-family: "Times New Roman", serif;">,</span>就會處於這個模式<span style="font-family: "Times New Roman", serif;">).</span></td></tr>
<tr class="alt" valign="TOP"><td height="20" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155"><span style="font-family: "Times New Roman", serif;">UND (Undefined)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">b11011</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Priviledged</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">未定義指令異常模式<span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當處理器遇到無法解譯的指令時<span style="font-family: "Times New Roman", serif;">,</span>會先跟<span style="font-family: "Times New Roman", serif;">Coprocessor </span>確認是否為<span style="font-family: "Times New Roman", serif;">Coprocessor</span>指令<span style="font-family: "Times New Roman", serif;">,</span>若不是<span style="font-family: "Times New Roman", serif;">,</span>就會觸發例外<span style="font-family: "Times New Roman", serif;">,</span>進入這個模式<span style="font-family: "Times New Roman", serif;">.</span>一般我們用軟體除錯器要設定中斷點時<span style="font-family: "Times New Roman", serif;">,</span>也可透過置入未定義的指令<span style="font-family: "Times New Roman", serif;">,</span>當作<span style="font-family: "Times New Roman", serif;">Break Point</span>之用<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
<tr valign="TOP"><td height="18" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="155"><span style="font-family: "Times New Roman", serif;">SYS</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="119"><span style="font-family: "Times New Roman", serif;">b11111</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="168"><span style="font-family: "Times New Roman", serif;">Priviledged</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="461">系統特權模式<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
跟<span style="font-family: "Times New Roman", serif;">User Mode</span>共用一致的暫存器<span style="font-family: "Times New Roman", serif;">(R0-R15/CPSR/SPSR),</span>主要的差別是<span style="font-family: "Times New Roman", serif;">User Mode</span>為<span style="font-family: "Times New Roman", serif;">Unpriviledged Mode.</span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在除錯時<span style="font-family: "Times New Roman", serif;">,</span>可以透過<span style="font-family: "Times New Roman", serif;">xPSR </span>的<span style="font-family: "Times New Roman", serif;">M[4:0] 5</span>個<span style="font-family: "Times New Roman", serif;">bits </span>判斷目前與前一個處理器狀態<span style="font-family: "Times New Roman", serif;">,</span>推測系統前後問題發生的原因<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>處理器有<span style="font-family: "Times New Roman", serif;">31</span>個<span style="font-family: "Times New Roman", serif;">(</span>不包含支援<span style="font-family: "Times New Roman", serif;">Security Extensions</span>上的<span style="font-family: "Times New Roman", serif;">Monitor Mode R13</span>與<span style="font-family: "Times New Roman", serif;">R14)32</span>位元通用暫存器<span style="font-family: "Times New Roman", serif;">(R0-R15,R13/R14_svc, R13/R14_abt, R13/R14_und, R13/R14_irq, R8-R14_fiq)</span>及<span style="font-family: "Times New Roman", serif;">6</span>個狀態暫存器<span style="font-family: "Times New Roman", serif;">(CPSR,SPSR_svc,SPSR_abt,SPSR_und,SPSR_irq,_SPSR_fiq)</span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 941px;"><colgroup><col width="110"></col><col width="98"></col><col width="75"></col><col width="74"></col><col width="83"></col><col width="81"></col><col width="92"></col><col width="87"></col><col width="90"></col><col width="110"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td colspan="3" height="39" rowspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="291"></td><td colspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="639"><span style="font-family: "Times New Roman", serif;">Priviledged Modes</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="562"><span style="font-family: "Times New Roman", serif;">Exception Modes</span></td></tr>
<tr class="alt" valign="TOP"><td height="40" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110">暫存器說明</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">Application<br />View</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">User Mode</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"><span style="font-family: "Times New Roman", serif;">System</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Mode</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">FIQ</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Mode</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"><span style="font-family: "Times New Roman", serif;">IRQ</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Mode</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"><span style="font-family: "Times New Roman", serif;">Supervisor</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Mode</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><span style="font-family: "Times New Roman", serif;">Abort</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Mode</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;">Undefined</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Mode</span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">Monitor</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Mode</span></div>
</td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110">函式傳遞參數<span style="font-family: "Times New Roman", serif;">#0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R0_usr</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr class="alt" valign="TOP"><td height="25" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110">函式傳遞參數<span style="font-family: "Times New Roman", serif;">#1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R1</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R1_usr</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr valign="TOP"><td height="22" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110">函式傳遞參數<span style="font-family: "Times New Roman", serif;">#2</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R2</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R2_usr</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr class="alt" valign="TOP"><td height="22" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110">函式傳遞參數<span style="font-family: "Times New Roman", serif;">#3</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R3</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R3_usr</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr valign="TOP"><td height="32" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R4_usr</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr class="alt" valign="TOP"><td height="29" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R5</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R5_usr</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr valign="TOP"><td height="26" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R6</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R6_usr</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr class="alt" valign="TOP"><td height="25" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R7</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R7_usr</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R8</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R8_usr</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">R8_fiq</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr class="alt" valign="TOP"><td height="26" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R9</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R9_usr</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">R9_fiq</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr valign="TOP"><td height="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R10</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R10_usr</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">R10_fiq</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr class="alt" valign="TOP"><td height="22" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R11</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R11_usr</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">R11_fiq</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr valign="TOP"><td height="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">R12</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">R12_usr</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">R12_fiq</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr class="alt" valign="TOP"><td height="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">SP</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">SP_usr</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">SP_fiq</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"><span style="font-family: "Times New Roman", serif;">SP_irq</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"><span style="font-family: "Times New Roman", serif;">SP_svc</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><span style="font-family: "Times New Roman", serif;">SP_abt</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;">SP_und</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">SP_mon</span></td></tr>
<tr valign="TOP"><td height="19" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">LR</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">LR_usr</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">LR_fiq</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"><span style="font-family: "Times New Roman", serif;">LR_irq</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"><span style="font-family: "Times New Roman", serif;">LR_svc</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><span style="font-family: "Times New Roman", serif;">LR_abt</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;">LR_und</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">LR_mon</span></td></tr>
<tr class="alt" valign="TOP"><td height="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">PC</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">PC</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr valign="TOP"><td height="33" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"><span style="font-family: "Times New Roman", serif;">APSR</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"><span style="font-family: "Times New Roman", serif;">CPSR</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td></tr>
<tr class="alt" valign="TOP"><td height="26" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="98"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="74"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="83"><span style="font-family: "Times New Roman", serif;">SPSR_fiq</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"><span style="font-family: "Times New Roman", serif;">SPSR_irq</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="92"><span style="font-family: "Times New Roman", serif;">SPSR_svc</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="87"><span style="font-family: "Times New Roman", serif;">SPSR_abt</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="90"><span style="font-family: "Times New Roman", serif;">SPSR_und</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">SPSR_mon</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般而言<span style="font-family: "Times New Roman", serif;">16bits Thumb Code</span>只會使用到<span style="font-family: "Times New Roman", serif;">R0-R7 (3bits Register Index),ARM 32-bits</span>指令集可以用到完整的<span style="font-family: "Times New Roman", serif;">R0-R12. </span>而<span style="font-family: "Times New Roman", serif;">R13(SP),R14(LR)</span>跟<span style="font-family: "Times New Roman", serif;">R15(PC)</span>是每個模式下都會使用到的<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除了有支援中斷向量表的處理器核心外<span style="font-family: "Times New Roman", serif;">(</span>例如<span style="font-family: "Times New Roman", serif;">:Cortex M3),</span>一般的<span style="font-family: "Times New Roman", serif;">ARM</span>核心主要支援以下八種中斷<span style="font-family: "Times New Roman", serif;">(</span>其中第六個中斷為<span style="font-family: "Times New Roman", serif;">Reserved),</span>可以透過修改<span style="font-family: "Times New Roman", serif;">CP15 c1</span>暫存器的<span style="font-family: "Times New Roman", serif;">V (bit13),</span>決定中斷表示在低位址 <span style="font-family: "Times New Roman", serif;">(V=0</span>則位於<span style="font-family: "Times New Roman", serif;">0x00000000-0x0000001C)</span>或高位址<span style="font-family: "Times New Roman", serif;">(V=1</span>則位於<span style="font-family: "Times New Roman", serif;">0xFFFF0000-0xFFFF001C). </span>若產品在開發初期<span style="font-family: "Times New Roman", serif;">,</span>而且又沒有<span style="font-family: "Times New Roman", serif;">MMU</span>透過<span style="font-family: "Times New Roman", serif;">User Mode/Priviledge Mode</span>機制做記憶體保護的環境<span style="font-family: "Times New Roman", serif;">,</span>建議可以把中斷表設置在高位置<span style="font-family: "Times New Roman", serif;">,</span>避免在產品開發階段<span style="font-family: "Times New Roman", serif;">,</span>因為空指標<span style="font-family: "Times New Roman", serif;">(NULL Pointer)</span>所導致的系統方面的錯誤<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一旦系統發生<span style="font-family: "Times New Roman", serif;">Exception,</span>首先會把目前的<span style="font-family: "Times New Roman", serif;">CPSR</span>儲存到發生<span style="font-family: "Times New Roman", serif;">Exception</span>對應模式下的<span style="font-family: "Times New Roman", serif;">SPRS(</span>可用來檢視進入<span style="font-family: "Times New Roman", serif;">Exception</span>前系統的狀態<span style="font-family: "Times New Roman", serif;">),</span>之後把<span style="font-family: "Times New Roman", serif;">PC</span>值加上<span style="font-family: "Times New Roman", serif;">Exception</span>對應的<span style="font-family: "Times New Roman", serif;">Offest</span>值<span style="font-family: "Times New Roman", serif;">(Exception-Dependent Offset)</span>後<span style="font-family: "Times New Roman", serif;">,</span>存在<span style="font-family: "Times New Roman", serif;">LR</span>中<span style="font-family: "Times New Roman", serif;">,</span>如下所示為每個<span style="font-family: "Times New Roman", serif;">Exeception Mode</span>對應的<span style="font-family: "Times New Roman", serif;">Exception-Dependent Offset</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 967px;"><colgroup><col width="110"></col><col width="200"></col><col width="188"></col><col width="198"></col><col width="220"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">Exception</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="200"><span style="font-family: "Times New Roman", serif;">Base LR Value</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">Offset for processor state of</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="198"><span style="font-family: "Times New Roman", serif;">Offset for processor state of</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Thumb of ThumbEE</span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">Offset for processor state of</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Jazelle</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">Undefine Instruction</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="200"><span style="font-family: "Times New Roman", serif;">Address of the undefined instruction</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="198"><span style="font-family: "Times New Roman", serif;">2</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">2 or 4</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">SVC</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="200"><span style="font-family: "Times New Roman", serif;">Address of SVC instruction</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="198"><span style="font-family: "Times New Roman", serif;">2</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">X</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">SMC</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="200"><span style="font-family: "Times New Roman", serif;">Address of SMC instruction</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="198"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">X</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">Prefetch Abort</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="200"><span style="font-family: "Times New Roman", serif;">Address of aborted instruction fetch</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="198"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">4</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">Data Abort</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="200"><span style="font-family: "Times New Roman", serif;">Address of inctruction that generated the abort</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">8</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="198"><span style="font-family: "Times New Roman", serif;">8</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">8</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="110"><span style="font-family: "Times New Roman", serif;">IRQ/FIQ</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="200"><span style="font-family: "Times New Roman", serif;">Address of next instruction to execute</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="188"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="198"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">4</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
之後根據<span style="font-family: "Times New Roman", serif;">Exception Handler</span>所在位置<span style="font-family: "Times New Roman", serif;">,</span>設定<span style="font-family: "Times New Roman", serif;">PC</span>值<span style="font-family: "Times New Roman", serif;">,</span>與更新<span style="font-family: "Times New Roman", serif;">CPSR Mode[4:0]</span>的內容為發生的<span style="font-family: "Times New Roman", serif;">Exception Mode,</span>關閉對應的中斷防止重入<span style="font-family: "Times New Roman", serif;">(</span>基本都會關閉<span style="font-family: "Times New Roman", serif;">IRQ,</span>而在<span style="font-family: "Times New Roman", serif;">FIQ,Secure Monitor</span>與<span style="font-family: "Times New Roman", serif;">Reset Mode</span>中會同時關閉<span style="font-family: "Times New Roman", serif;">IRQ </span>與<span style="font-family: "Times New Roman", serif;">FIQ). </span>並參考<span style="font-family: "Times New Roman", serif;">CP15 c1</span>暫存器的<span style="font-family: "Times New Roman", serif;">TE (bit30),</span>決定<span style="font-family: "Times New Roman", serif;">Exception Handler</span>是用哪個處理器指令集狀態執行<span style="font-family: "Times New Roman", serif;">. (TE=0 </span>表示 <span style="font-family: "Times New Roman", serif;">Exception</span>採<span style="font-family: "Times New Roman", serif;">ARM</span>指令集<span style="font-family: "Times New Roman", serif;">,TE=1</span>則為<span style="font-family: "Times New Roman", serif;">Thumb</span>指令集<span style="font-family: "Times New Roman", serif;">),</span>參考<span style="font-family: "Times New Roman", serif;">Exception Mode</span>的<span style="font-family: "Times New Roman", serif;">CPSR E(bit9)</span>決定<span style="font-family: "Times New Roman", serif;">Exception</span>執行時的<span style="font-family: "Times New Roman", serif;">Data Endian,</span>設定<span style="font-family: "Times New Roman", serif;">CPSR IT[7:0]</span>為<span style="font-family: "Times New Roman", serif;">0.</span>之後便開始<span style="font-family: "Times New Roman", serif;">Exception Handler</span>的執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果我們希望讓<span style="font-family: "Times New Roman", serif;">ARM</span>處於<span style="font-family: "Times New Roman", serif;">Suspend</span>進入低耗電的狀態<span style="font-family: "Times New Roman", serif;">(</span>類似對裝置<span style="font-family: "Times New Roman", serif;">Clock Gating,</span>只是並沒有透過<span style="font-family: "Times New Roman", serif;">PMIC</span>關閉電源<span style="font-family: "Times New Roman", serif;">),</span>也可以透過<span style="font-family: "Times New Roman", serif;">WFI(Wait For Interrupt)</span>指令<span style="font-family: "Times New Roman", serif;">,</span>讓<span style="font-family: "Times New Roman", serif;">ARM</span>等待外部中斷例如<span style="font-family: "Times New Roman", serif;">:IRQ</span>或<span style="font-family: "Times New Roman", serif;">FIQ,</span>對產品端而言就是手機的按鍵或是透過<span style="font-family: "Times New Roman", serif;">Real-Time Clock</span>的中斷<span style="font-family: "Times New Roman", serif;">,</span>喚醒處理器<span style="font-family: "Times New Roman", serif;">,</span>恢復正常的執行<span style="font-family: "Times New Roman", serif;">.</span>反之<span style="font-family: "Times New Roman", serif;">,</span>也可以透過<span style="font-family: "Times New Roman", serif;">System Controller</span>關閉處理器的電源<span style="font-family: "Times New Roman", serif;">(</span>進入<span style="font-family: "Times New Roman", serif;">Doze Mode),</span>只是相對於<span style="font-family: "Times New Roman", serif;">WFI,</span>會變成處理器要重新<span style="font-family: "Times New Roman", serif;">Re-initialize,</span>相關的狀態還要預存在<span style="font-family: "Times New Roman", serif;">TCM(Tightly-Couple Memory),</span>這需要針對產品端要達成的目的來做設計上的評估<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
通常<span style="font-family: "Times New Roman", serif;">,WFI</span>可以放在系統<span style="font-family: "Times New Roman", serif;">Idle Task</span>的實作中<span style="font-family: "Times New Roman", serif;">,</span>如果沒有相關需要處理的工作等待執行<span style="font-family: "Times New Roman", serif;">,</span>系統就會把執行權交到最低優先級的<span style="font-family: "Times New Roman", serif;">Idle Task</span>中<span style="font-family: "Times New Roman", serif;">,</span>再由<span style="font-family: "Times New Roman", serif;">Idle Task</span>判斷系統中下一次會醒過來的時間點<span style="font-family: "Times New Roman", serif;">,</span>決定是不是要把外部記憶體設定為省電模式<span style="font-family: "Times New Roman", serif;">,</span>並讓處理器透過<span style="font-family: "Times New Roman", serif;">WFI</span>進入<span style="font-family: "Times New Roman", serif;">Suspend</span>低耗電的狀態<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為對應的類型<span style="font-family: "Times New Roman", serif;">,</span>優先級與中斷記憶體位置<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(</span>參考<span style="font-family: "Times New Roman", serif;">:ARMv7-AR Architecture Reference Manual).</span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 965px;"><colgroup><col width="131"></col><col width="100"></col><col width="63"></col><col width="137"></col><col width="512"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td height="24" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131">中斷位址</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">中斷類型</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63">優先級</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137">對應處理器模式</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512">發生時處理器對應的動作<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr valign="TOP"><td height="10" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131"><span style="font-family: "Times New Roman", serif;">0x0000-0000<br />(0xFFFF-0000)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">系統重置<span style="font-family: "Times New Roman", serif;"><br />Reset</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137"><span style="font-family: "Times New Roman", serif;">SVC</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">TakeReset()</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Enter Supervisor mode and (if relevant) Secure state, and reset CP15. This affects the banked versions and values of various registers accessed later in the code. Also reset other system components.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.M = ‘10011’; // Supervisor mode</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if HaveSecurityExt() then SCR.NS = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">ResetCP15Registers();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">ResetDebugRegisters();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if HaveAdvSIMDorVFP() then FPEXC.EN = ‘0’; SUBARCHITECTURE_DEFINED further resetting;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if HaveThumbEE() then TEECR.XED = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if HaveJazelle() then JMCR.JE = ‘0’; SUBARCHITECTURE_DEFINED further resetting;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Further CPSR changes: all interrupts disabled, IT state reset, instruction set and endianness according to the SCTLR values produced by the above call to ResetCP15Registers().</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.I = ‘1’; CPSR.F = ‘1’; CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.IT = ‘00000000’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: ARM, TE=1: Thumb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// All registers, bits and fields not reset by the above pseudocode or by the BranchTo() call below are UNKNOWN bitstrings after reset. In particular, the return information registers R14_svc and SPSR_svc have UNKNOWN values, so that it is impossible to return from a reset in an architecturally defined way. Branch to Reset vector.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(ExcVectorBase() + 0);</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="24" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131"><span style="font-family: "Times New Roman", serif;">0x0000-0004<br />(0xFFFF-0004)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">未定義指令集<span style="font-family: "Times New Roman", serif;"><br />Undefined Instruction</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;">6</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137"><span style="font-family: "Times New Roman", serif;">UND</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">TakeUndefInstrException()</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine return information. SPSR is to be the current CPSR, and LR is to be the current PC minus 2 for Thumb or 4 for ARM, to change the PC offsets of 4 or 8 respectively from the address of the current instruction into the required return address offsets of 2 or 4 respectively.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_lr_value = if CPSR.T == ‘1’ then PC-2 else PC-4;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_spsr_value = CPSR;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Enter Undefined (‘11011’) mode, and ensure Secure state if initially in Monitor (‘10110’) mode. This affects the banked versions of various registers accessed later in the code.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if CPSR.M == ‘10110’ then SCR.NS = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.M = ‘11011’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Write return information to registers, and make further CPSR changes: IRQs disabled, IT state reset, instruction set and endianness to SCTLR-configured values.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">SPSR[] = new_spsr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">R[14] = new_lr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.I = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.IT = ‘00000000’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: ARM, TE=1: Thumb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Branch to Undefined Instruction vector.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(ExcVectorBase() + 4);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">////</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">ARMv7</span></span></span><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">架構下</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">也可以讓</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">Undefined Instruction</span></span></span><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">執行類似</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">NOP</span></span></span><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">的動作</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">處理器不會觸發</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">Exception,</span></span></span><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">只是忽略該指令的執行</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></div>
</td></tr>
<tr valign="TOP"><td height="23" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131"><span style="font-family: "Times New Roman", serif;">0x0000-0008<br />(0xFFFF-0008)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">軟體中斷<span style="font-family: "Times New Roman", serif;"><br />SWI</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Secure Monitor Call (SMC)</span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;">6</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137"><span style="font-family: "Times New Roman", serif;">SVC </span>或<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">SMC Mode</span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">TakeSVCException()</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine return information. SPSR is to be the current CPSR, after changing the IT[] bits to give them the correct values for the following instruction, and LR is to be the current PC minus 2 for Thumb or 4 for ARM, to change the PC offsets of 4 or 8 respectively from the address of the current instruction into the required address of the next instruction (the SVC instruction having size 2 or 4 bytes respectively).</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">ITAdvance();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_lr_value = if CPSR.T == ‘1’ then PC-2 else PC-4;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_spsr_value = CPSR;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Enter Supervisor (‘10011’) mode, and ensure Secure state if initially in Monitor (‘10110’) mode. This affects the banked versions of various registers accessed later in the code.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if CPSR.M == ‘10110’ then SCR.NS = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.M = ‘10011’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Write return information to registers, and make further CPSR changes: IRQs disabled, IT state reset, instruction set and endianness to SCTLR-configured values.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">SPSR[] = new_spsr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">R[14] = new_lr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.I = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.IT = ‘00000000’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: ARM, TE=1: Thumb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Branch to SVC vector.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(ExcVectorBase() + 8);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">或</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">TakeSMCException()</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine return information. SPSR is to be the current CPSR, after changing the IT[] bits to give them the correct values for the following instruction, and LR is to be the current PC minus 0 for Thumb or 4 for ARM, to change the PC offsets of 4 or 8 respectively from the address of the current instruction into the required address of the next instruction (with the SMC instruction always being 4 bytes in length).</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">ITAdvance();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_lr_value = if CPSR.T == ‘1’ then PC else PC-4;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_spsr_value = CPSR;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Enter Monitor (‘10110’) mode, and ensure Secure state if initially in Monitor mode. This affects the banked versions of various registers accessed later in the code.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if CPSR.M == ‘10110’ then SCR.NS = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.M = ‘10110’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Write return information to registers, and make further CPSR changes: interrupts disabled, IT state reset, instruction set and endianness to SCTLR-configured values.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">SPSR[] = new_spsr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">R[14] = new_lr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.I = ‘1’; CPSR.F = ‘1’; CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.IT = ‘00000000’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: ARM, TE=1: Thumb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Branch to SMC vector.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(MVBAR + 8);</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="22" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131"><span style="font-family: "Times New Roman", serif;">0x0000-000C<br />(0xFFFF-000C)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">指令記憶體存取錯誤<span style="font-family: "Times New Roman", serif;"><br />Prefetch Abort</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;">5</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137"><span style="font-family: "Times New Roman", serif;">ABT</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">TakePrefetchAbortException()</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine return information. SPSR is to be the current CPSR, and LR is to be the current PC minus 0 for Thumb or 4 for ARM, to change the PC offsets of 4 or 8 respectively from the address of the current instruction into the required address of the current instruction plus 4.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_lr_value = if CPSR.T == ‘1’ then PC else PC-4;</span></span><span style="font-family: Helvetica-Oblique, sans-serif;"><span style="font-size: xx-small;"><em></em></span></span><span style="font-family: Helvetica, Arial, sans-serif;"><span style="font-size: xx-small;"><em></em></span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_spsr_value = CPSR;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine whether this is an external abort to be trapped to Monitor mode.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">trap_to_monitor = HaveSecurityExt() && SCR.EA == ‘1’ && IsExternalAbort();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Enter Abort (‘10111’) or Monitor (‘10110’) mode, and ensure Secure state if initially in Monitor mode. This affects the banked versions of various registers accessed later in the code.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if CPSR.M == ‘10110’ then SCR.NS = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.M = if trap_to_monitor then ‘10110’ else ‘10111’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Write return information to registers, and make further CPSR changes: IRQs disabled, other interrupts disabled if appropriate, IT state reset, instruction set and endianness to SCTLR-configured values.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">SPSR[] = new_spsr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">R[14] = new_lr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.I = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if trap_to_monitor then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.F = ‘1’; CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">else</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if !HaveSecurityExt() || SCR.NS == ‘0’ || SCR.AW == ‘1’ then CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.IT = ‘00000000’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: ARM, TE=1: Thumb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Branch to correct Prefetch Abort vector.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if trap_to_monitor then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(MVBAR + 12);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">else</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(ExcVectorBase() + 12);</span></span></div>
</td></tr>
<tr class="" valign="TOP"><td height="21" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131"><span style="font-family: "Times New Roman", serif;">0x0000-0010<br />(0xFFFF-0010)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">資料記憶體存取錯誤<span style="font-family: "Times New Roman", serif;"><br />Data Abort</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;">2</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137"><span style="font-family: "Times New Roman", serif;">ABT</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">TakeDataAbortException()</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine return information. SPSR is to be the current CPSR, and LR is to be the current PC plus 4 for Thumb or 0 for ARM, to change the PC offsets of 4 or 8 respectively from the address of the current instruction into the required address of the current instruction plus 8. For an asynchronous abort, the PC and CPSR are considered to have already moved on to their values for the instruction following the instruction boundary at which the exception occurred.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_lr_value = if CPSR.T == ‘1’ then PC+4 else PC;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_spsr_value = CPSR;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine whether this is an external abort to be trapped to Monitor mode.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">trap_to_monitor = HaveSecurityExt() && SCR.EA == ‘1’ && IsExternalAbort();</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Enter Abort (‘10111’) or Monitor (‘10110’) mode, and ensure Secure state if initially in Monitor mode. This affects the banked versions of various registers accessed later in the code.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if CPSR.M == ‘10110’ then SCR.NS = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.M = if trap_to_monitor then ‘10110’ else ‘10111’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Write return information to registers, and make further CPSR changes: IRQs disabled, other interrupts disabled if appropriate, IT state reset, instruction set and endianness to SCTLR-configured values.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">SPSR[] = new_spsr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">R[14] = new_lr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.I = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if trap_to_monitor then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.F = ‘1’; CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">else</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if !HaveSecurityExt() || SCR.NS == ‘0’ || SCR.AW == ‘1’ then CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.IT = ‘00000000’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Helvetica-Oblique, sans-serif;"><span style="font-size: xx-small;"><em>The System Level Programmers’ Model</em></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: Helvetica, Arial, sans-serif;"><span style="font-size: xx-small;">ARM DDI 0406B </span></span><span style="font-family: Helvetica-Oblique, sans-serif;"><span style="font-size: xx-small;"><em>Copyright © 1996-1998, 2000, 2004-2008 ARM Limited. All rights reserved.</em></span></span><span style="font-family: Helvetica, Arial, sans-serif;"><span style="font-size: xx-small;">B1-57</span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: ARM, TE=1: Thumb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Branch to correct Data Abort vector.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if trap_to_monitor then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(MVBAR + 16);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">else</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(ExcVectorBase() + 16);</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131"><span style="font-family: "Times New Roman", serif;">0x0000-0014<br />(0xFFFF-0014)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">保留</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63">未使用</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512"></td></tr>
<tr class="" valign="TOP"><td height="19" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131"><span style="font-family: "Times New Roman", serif;">0x0000-0018<br />(0xFFFF-0018)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">外部一般中斷模式<span style="font-family: "Times New Roman", serif;"><br />IRQ</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137"><span style="font-family: "Times New Roman", serif;">IRQ</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">TakeIRQException()</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine return information. SPSR is to be the current CPSR, and LR is to be the current PC minus 0 for Thumb or 4 for ARM, to change the PC offsets of 4 or 8 respectively from the address of the current instruction into the required address of the instruction boundary at which the interrupt occurred plus 4. For this purpose, the PC and CPSR are considered to have already moved on to their values for the instruction following that boundary.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_lr_value = if CPSR.T == ‘1’ then PC else PC-4;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_spsr_value = CPSR;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine whether IRQs are trapped to Monitor mode.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">trap_to_monitor = HaveSecurityExt() && SCR.IRQ == ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Enter IRQ (‘10010’) or Monitor (‘10110’) mode, and ensure Secure state if initially in Monitor mode. This affects the banked versions of various registers accessed later in the code.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if CPSR.M == ‘10110’ then SCR.NS = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.M = if trap_to_monitor then ‘10110’ else ‘10010’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Write return information to registers, and make further CPSR changes: IRQs disabled, other interrupts disabled if appropriate, IT state reset, instruction set and endianness to SCTLR-configured values.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">SPSR[] = new_spsr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">R[14] = new_lr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.I = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if trap_to_monitor then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.F = ‘1’; CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">else</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if !HaveSecurityExt() || SCR.NS == ‘0’ || SCR.AW == ‘1’ then CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.IT = ‘00000000’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: ARM, TE=1: Thumb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Branch to correct IRQ vector.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if trap_to_monitor then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(MVBAR + 24);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">elsif SCTLR.VE == ‘1’ then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">IMPLEMENTATION_DEFINED branch to an IRQ vector;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">else</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(ExcVectorBase() + 24);</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="16" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="131"><span style="font-family: "Times New Roman", serif;">0x0000-001C<br />(0xFFFF-001C)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">快速中斷<span style="font-family: "Times New Roman", serif;"><br />FIQ</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;">3</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="137"><span style="font-family: "Times New Roman", serif;">FIQ</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="512"><span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">TakeFIQException()</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine return information. SPSR is to be the current CPSR, and LR is to be the current PC minus 0 for Thumb or 4 for ARM, to change the PC offsets of 4 or 8 respectively from the address of the current instruction into the required address of the instruction boundary at which the interrupt occurred plus 4. For this purpose, the PC and CPSR are considered to have already moved on to their values for the instruction following that boundary.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_lr_value = if CPSR.T == ‘1’ then PC else PC-4;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">new_spsr_value = CPSR;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Determine whether FIQs are trapped to Monitor mode.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">trap_to_monitor = HaveSecurityExt() && SCR.FIQ == ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Enter FIQ (‘10001’) or Monitor (‘10110’) mode, and ensure Secure state if initially in Monitor mode. This affects the banked versions of various registers accessed later in the code.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if CPSR.M == ‘10110’ then SCR.NS = ‘0’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.M = if trap_to_monitor then ‘10110’ else ‘10001’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Write return information to registers, and make further CPSR changes: IRQs disabled, other interrupts disabled if appropriate, IT state reset, instruction set and endianness to SCTLR-configured values.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">SPSR[] = new_spsr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">R[14] = new_lr_value;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.I = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if trap_to_monitor then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.F = ‘1’; CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">else</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if !HaveSecurityExt() || SCR.NS == ‘0’ || SCR.FW == ‘1’ then CPSR.F = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if !HaveSecurityExt() || SCR.NS == ‘0’ || SCR.AW == ‘1’ then CPSR.A = ‘1’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.IT = ‘00000000’;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: ARM, TE=1: Thumb</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">// Branch to correct FIQ vector.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">if trap_to_monitor then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(MVBAR + 28);</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">elsif SCTLR.VE == ‘1’ then</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">IMPLEMENTATION_DEFINED branch to an FIQ vector;</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">else</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: xx-small;">BranchTo(ExcVectorBase() + 28);</span></span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以<span style="font-family: "Times New Roman", serif;">Abort Mode</span>的行為來說<span style="font-family: "Times New Roman", serif;">,</span>當系統發生<span style="font-family: "Times New Roman", serif;">Abort</span>中斷時<span style="font-family: "Times New Roman", serif;">,</span>會把<span style="font-family: "Times New Roman", serif;">IRQ</span>關閉<span style="font-family: "Times New Roman", serif;">,FIQ</span>狀態仍維持開啟<span style="font-family: "Times New Roman", serif;">,</span>根據開發使用的<span style="font-family: "Times New Roman", serif;">SoC</span>不同<span style="font-family: "Times New Roman", serif;">,</span>如果你所使用的晶片<span style="font-family: "Times New Roman", serif;">,</span>有把其他中斷來源接到<span style="font-family: "Times New Roman", serif;">FIQ(</span>例如<span style="font-family: "Times New Roman", serif;">:Timer),</span>就會需要在<span style="font-family: "Times New Roman", serif;">Abort</span>中斷處理中<span style="font-family: "Times New Roman", serif;">,</span>立刻關閉<span style="font-family: "Times New Roman", serif;">FIQ,</span>以避免在<span style="font-family: "Times New Roman", serif;">Abort Mode</span>時<span style="font-family: "Times New Roman", serif;">,</span>有其他中斷的重入<span style="font-family: "Times New Roman", serif;">,</span>導致分析系統問題時<span style="font-family: "Times New Roman", serif;">,</span>不容易定位真正的問題<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>處理器的<span style="font-family: "Times New Roman", serif;">Cache,MMU</span>與<span style="font-family: "Times New Roman", serif;">MPU</span>管理機制是透過<span style="font-family: "Times New Roman", serif;">Coprocessor #15</span>實現的<span style="font-family: "Times New Roman", serif;">,</span>當今天系統發生處理器的<span style="font-family: "Times New Roman", serif;">PC</span>值指到一個無效的記憶體位置時<span style="font-family: "Times New Roman", serif;">,</span>就會觸發<span style="font-family: "Times New Roman", serif;">Prefetch Abort,</span>然後處理器會更新<span style="font-family: "Times New Roman", serif;">Coprocessor #15</span>中的<span style="font-family: "Times New Roman", serif;">IFSR(Instruction Fault Status Register) </span>的錯誤狀態碼<span style="font-family: "Times New Roman", serif;">,</span>以及更新<span style="font-family: "Times New Roman", serif;">IFAR(Instruction Fault Address Register)</span>紀錄觸發<span style="font-family: "Times New Roman", serif;">Prefetch Abort</span>的記憶體位置<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">IFSR</span>為一個<span style="font-family: "Times New Roman", serif;">32bits</span>可讀可寫的暫存器<span style="font-family: "Times New Roman", serif;">,</span>只有在特權等級模式下才可以讀取<span style="font-family: "Times New Roman", serif;">,IFSR</span>格式說明如下</div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 913px;"><colgroup><col width="100"></col><col width="161"></col><col width="638"></col></colgroup><tbody>
<tr valign="TOP"><td height="23" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">位元</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161">功能</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638">說明</td></tr>
<tr class="alt" valign="TOP"><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">31-13</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: Gen_Times-New-Roman;"><span style="font-size: xx-small;">UNK/SBZP</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Gen_Times-New-Roman;"><span style="font-size: xx-small;">(Bits [31:13,11,9:4])</span></span></div>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">UNK/SBZP</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">unknown on reads, Should-Be-Zero-or-Preserved on writes.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">12</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">ExT</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">External abort type.</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">11</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"></td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">10</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">FS[4]</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Fault status bits.</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">9 – 4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: Gen_Times-New-Roman;"><span style="font-size: xx-small;">UNK/SBZP</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">UNK/SBZP</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">unknown on reads, Should-Be-Zero-or-Preserved on writes.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="13" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">3-0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">FS[3:0]</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Fault status bits.</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以透過<span style="font-family: "Times New Roman", serif;">CP15</span>的指令進行<span style="font-family: "Times New Roman", serif;">IFSR</span>的讀寫動作<span style="font-family: "Times New Roman", serif;">,</span>如下例子</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MRC p15,0,<Rt>,c5,c0,1 ; Read CP15 Instruction Fault Status Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MCR p15,0,<Rt>,c5,c0,1 ; Write CP15 Instruction Fault Status Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">IFAR</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">為一個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">可讀可寫的暫存器</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">只有在特權等級模式下才可以讀取</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,IFAR</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Prefetch Abort</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">時</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">可用來反映出發生</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Abort</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">時所在的記憶體位址</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">可以透過</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CP15</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">的指令進行</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">IFAR</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">的讀寫動作</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">如下例子</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MRC p15,0,<Rt>,c6,c0,2 ; Read CP15 Instruction Fault Address Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MCR p15,0,<Rt>,c6,c0,2 ; Write CP15 Instruction Fault Address Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DFSR</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">為一個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">可讀可寫的暫存器</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">只有在特權等級模式下才可以讀取</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,DFSR</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">格式說明如下</span></span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 913px;"><colgroup><col width="100"></col><col width="161"></col><col width="638"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td height="23" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">位元</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161">功能</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638">說明</td></tr>
<tr valign="TOP"><td height="27" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">31-13</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: Gen_Times-New-Roman;"><span style="font-size: xx-small;">UNK/SBZP</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Gen_Times-New-Roman;"><span style="font-size: xx-small;">(Bits [31:13,9:8])</span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">UNK/SBZP</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">unknown on reads, Should-Be-Zero-or-Preserved on writes.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">12</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">ExT</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">External abort type.</span></td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">11</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">WnR</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Write not Read bit.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Indicates whether the abort was caused by a write or a read access:</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0 Abort caused by a read access</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1 Abort caused by a write access.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">For faults on CP15 cache maintenance operations, including the VA to PA translation operations, this bit always returns a value of 1.</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">10</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">FS[4]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Fault status bits.</span></span></td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">9 — 8</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: Gen_Times-New-Roman;"><span style="font-size: xx-small;">b00</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"></td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">7–4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: Gen_Times-New-Roman;"><span style="font-size: xx-small;">Domain</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">The domain of the fault address.</span></td></tr>
<tr valign="TOP"><td height="13" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">3-0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">FS[3:0]</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Fault status bits.</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以透過<span style="font-family: "Times New Roman", serif;">CP15</span>的指令進行<span style="font-family: "Times New Roman", serif;">DFSR</span>的讀寫動作<span style="font-family: "Times New Roman", serif;">,</span>如下例子</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MRC p15,0,<Rt>,c5,c0,0 ; Read CP15 Data Fault Status Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MCR p15,0,<Rt>,c5,c0,0 ; Write CP15 Data Fault Status Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DFAR</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">為一個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">可讀可寫的暫存器</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">只有在特權等級模式下才可以讀取</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,DFAR</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Data Abort</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">時</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">可用來反映出發生</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Abort</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">時所存取的記憶體位址</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">可以透過</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CP15</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">的指令進行</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">DFAR</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">的讀寫動作</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">如下例子</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MRC p15,0,<Rt>,c6,c0,0 ; Read CP15 Data Fault Address Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MCR p15,0,<Rt>,c6,c0,0 ; Write CP15 Data Fault Address Register</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
隨著<span style="font-family: "Times New Roman", serif;">ARMv7</span>架構的出現<span style="font-family: "Times New Roman", serif;">,ARM</span>目前所支援的指令集包括了<span style="font-family: "Times New Roman", serif;">ARMv32,Thumb,Thumb2,ThumbEE(Thumb Execution Environment),</span>與<span style="font-family: "Times New Roman", serif;">Jazelle,</span>我們可以透過<span style="font-family: "Times New Roman", serif;">CPSR(Current Program Status Register)</span>中的<span style="font-family: "Times New Roman", serif;">J</span>與<span style="font-family: "Times New Roman", serif;">T bits(</span>位於<span style="font-family: "Times New Roman", serif;">CPSR</span>第<span style="font-family: "Times New Roman", serif;">24</span>與第<span style="font-family: "Times New Roman", serif;">5</span>個<span style="font-family: "Times New Roman", serif;">bit) </span>來判斷目前處理器所處的狀態<span style="font-family: "Times New Roman", serif;">,</span>如下所示<span style="font-family: "Times New Roman", serif;">(</span>參考 <span style="font-family: "Times New Roman", serif;">ARMv7-AR Architecture Reference Manual)</span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 553px;"><colgroup><col width="85"></col><col width="101"></col><col width="353"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td height="21" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="85"><h4 id="14512_j_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">J</span></span></h4>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><h4 id="14512_t_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">T</span></span></h4>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="353"><h4 id="14512_instruction-set-stat_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Instruction set state</span></span></h4>
</td></tr>
<tr valign="TOP"><td height="21" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="85"><h4 id="14512_0_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span></h4>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><h4 id="14512_0_2" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span></h4>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="353"><h4 id="14512_arm_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span></h4>
</td></tr>
<tr class="alt" valign="TOP"><td height="19" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="85"><h4 id="14512_0_3" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span></h4>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><h4 id="14512_1_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1</span></span></h4>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="353"><h4 id="14512_thumb_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Thumb</span></span></h4>
</td></tr>
<tr valign="TOP"><td height="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="85"><h4 id="14512_1_2" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1</span></span></h4>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><h4 id="14512_0_4" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span></h4>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="353"><h4 id="14512_jazelle_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle</span></span></h4>
</td></tr>
<tr class="alt" valign="TOP"><td height="20" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="85"><h4 id="14512_1_3" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1</span></span></h4>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="101"><h4 id="14512_1_4" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1</span></span></h4>
</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="353"><h4 id="14512_thumbee_1" style="font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ThumbEE</span></span></h4>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">參考如下的模擬程式碼</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">參考文件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">:ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition)</span></span><span style="font-size: x-small;">,</span><span style="font-size: x-small;">上述四個指令集除了由</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ThumbEE</span></span><span style="font-size: x-small;">切到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARMv32 Mode</span></span><span style="font-size: x-small;">是不能直接切換外</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">其它的模式都是可以依據需求直接的切換</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">切換的方式則是透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Branch Exchange</span></span><span style="font-size: x-small;">指令</span><span style="font-size: x-small;">轉換</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">指令集狀態</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>// CurrentInstrSet()</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>// =================</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>InstrSet CurrentInstrSet()</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>case ISETSTATE of</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>when ‘00’ result = InstrSet_ARM;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>when ‘01’ result = InstrSet_Thumb;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>when ‘10’ result = InstrSet_Jazelle;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>when ‘11’ result = InstrSet_ThumbEE;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>return result;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>// SelectInstrSet()</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>// ================</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>SelectInstrSet(InstrSet iset)</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>case iset of</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>when InstrSet_ARM</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>if CurrentInstrSet() == InstrSet_ThumbEE then</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>UNPREDICTABLE;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>else</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>ISETSTATE = ‘00’;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>when InstrSet_Thumb</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>ISETSTATE = ‘01’;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>when InstrSet_Jazelle</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>ISETSTATE = ‘10’;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>when InstrSet_ThumbEE</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>ISETSTATE = ‘11’;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: LucidaSansTypewriteX, sans-serif;"><span style="font-size: x-small;"><strong>return;</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據不同版本的<span style="font-family: "Times New Roman", serif;">ARM</span>核心設計<span style="font-family: "Times New Roman", serif;">,</span>像是在<span style="font-family: "Times New Roman", serif;">ARMv4T</span>中有支援<span style="font-family: "Times New Roman", serif;">Thumb</span>指令集<span style="font-family: "Times New Roman", serif;">,</span>會在三階的<span style="font-family: "Times New Roman", serif;">Pipeline</span>中的<span style="font-family: "Times New Roman", serif;">Decode</span>階段<span style="font-family: "Times New Roman", serif;">,</span>把<span style="font-family: "Times New Roman", serif;">16bits</span>的<span style="font-family: "Times New Roman", serif;">Thumb Code</span>轉碼為<span style="font-family: "Times New Roman", serif;">32bits</span>的對應<span style="font-family: "Times New Roman", serif;">ARM Code,</span>作為後續處理<span style="font-family: "Times New Roman", serif;">,</span>或像是<span style="font-family: "Times New Roman", serif;">ARMv7</span>的架構下<span style="font-family: "Times New Roman", serif;">,</span>有導入<span style="font-family: "Times New Roman", serif;">Superscalar</span>的<span style="font-family: "Times New Roman", serif;">Pipeline,</span>每次取指令時就會根據目前所在的指令集狀態<span style="font-family: "Times New Roman", serif;">,</span>一次抓取<span style="font-family: "Times New Roman", serif;">2</span>個<span style="font-family: "Times New Roman", serif;">32bits ARM</span>指令或是抓取<span style="font-family: "Times New Roman", serif;">2</span>個<span style="font-family: "Times New Roman", serif;">16bits Thumb</span>指令進行後續<span style="font-family: "Times New Roman", serif;">Pipeline</span>平行處理<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般我們在系統軟體設計時<span style="font-family: "Times New Roman", serif;">,</span>會根據所使用的處理器評估應該要採用哪種指令集<span style="font-family: "Times New Roman", serif;">,</span>得到產品端的效益<span style="font-family: "Times New Roman", serif;">,</span>例如<span style="font-family: "Times New Roman", serif;">ARM</span>指令集效能最高<span style="font-family: "Times New Roman", serif;">,</span>但因為都固定為<span style="font-family: "Times New Roman", serif;">32bits,</span>所編譯出來的程式碼較大<span style="font-family: "Times New Roman", serif;">,</span>而<span style="font-family: "Times New Roman", serif;">Thumb</span>指令集長度固定為<span style="font-family: "Times New Roman", serif;">16bits,</span>編譯後的程式碼大約只有<span style="font-family: "Times New Roman", serif;">ARM</span>程式的<span style="font-family: "Times New Roman", serif;">70%,</span>而效能也只約等同於<span style="font-family: "Times New Roman", serif;">ARM</span>直行效能的<span style="font-family: "Times New Roman", serif;">70%.</span>若你所使用的處理器有支援<span style="font-family: "Times New Roman", serif;">Thumb2,</span>如果所開發的模組為<span style="font-family: "Times New Roman", serif;">Video Codec,</span>為了得到比較好的影音效果<span style="font-family: "Times New Roman", serif;">,</span>選擇<span style="font-family: "Times New Roman", serif;">ARM</span>指令集會是比較好的<span style="font-family: "Times New Roman", serif;">,</span>若所開發的模組是屬於人機介面或是對效能要求有限的<span style="font-family: "Times New Roman", serif;">,</span>則選擇<span style="font-family: "Times New Roman", serif;">Thumb</span>或<span style="font-family: "Times New Roman", serif;">Thumb2</span>指令集會是一個節省記憶體空間的方式<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關<span style="font-family: "Times New Roman", serif;">ARM,Thumb,Thumb2</span>效能的比較可以參考這篇在<span style="font-family: "Times New Roman", serif;">ARM</span>工作的<span style="font-family: "Times New Roman", serif;">Richard Phelan</span>所寫的文章<span style="font-family: "Times New Roman", serif;">Improving ARM Code Density and Performance (<span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://www.cs.uiuc.edu/class/fa05/cs433ug/PROCESSORS/Thumb2.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.cs.uiuc.edu/class/fa05/cs433ug/PROCESSORS/Thumb2.pdf</a></span></span>), </span>以<span style="font-family: "Times New Roman", serif;">C Code</span>實作同樣的功能來說<span style="font-family: "Times New Roman", serif;">,</span>編譯為<span style="font-family: "Times New Roman", serif;">Thumb2</span>最高可以達到<span style="font-family: "Times New Roman", serif;">98%</span>的<span style="font-family: "Times New Roman", serif;">ARM</span>指令及效能<span style="font-family: "Times New Roman", serif;">,</span>程式碼本身所需的記憶體空間只占原本<span style="font-family: "Times New Roman", serif;">ARM</span>程式碼的<span style="font-family: "Times New Roman", serif;">74%.</span>再舉一個比較的例子<span style="font-family: "Times New Roman", serif;">,</span>以一個<span style="font-family: "Times New Roman", serif;">1MB</span>大小的<span style="font-family: "Times New Roman", serif;">ARM+Thumb</span>程式碼來說<span style="font-family: "Times New Roman", serif;">,</span>原本屬於<span style="font-family: "Times New Roman", serif;">ARM</span>的<span style="font-family: "Times New Roman", serif;">Code</span>佔<span style="font-family: "Times New Roman", serif;">200kbytes,</span>屬於<span style="font-family: "Times New Roman", serif;">Thumbv4</span>的<span style="font-family: "Times New Roman", serif;">Code</span>佔<span style="font-family: "Times New Roman", serif;">800kbytes,</span>如果全部都編譯為<span style="font-family: "Times New Roman", serif;">Thumb2,ARM</span>部分的<span style="font-family: "Times New Roman", serif;">Code</span>會成<span style="font-family: "Times New Roman", serif;">200kbytes</span>降為<span style="font-family: "Times New Roman", serif;">150kbytes,Thumbv4</span>的<span style="font-family: "Times New Roman", serif;">Code</span>會從<span style="font-family: "Times New Roman", serif;">800kbytes</span>降為<span style="font-family: "Times New Roman", serif;">760kbytes,</span>可以節省大約<span style="font-family: "Times New Roman", serif;">90kbytes</span>的程式碼空間<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
上述優化的數字<span style="font-family: "Times New Roman", serif;">,</span>還是要根據開發者所使用的處理器版本 <span style="font-family: "Times New Roman", serif;">(</span>會對應到不同的<span style="font-family: "Times New Roman", serif;">Thumb</span>與<span style="font-family: "Times New Roman", serif;">Thumb2</span>指令集版本<span style="font-family: "Times New Roman", serif;">),</span>與在編譯時所帶入的參數<span style="font-family: "Times New Roman", serif;">,</span>以<span style="font-family: "Times New Roman", serif;">RVCT</span>為例<span style="font-family: "Times New Roman", serif;">,</span>不論使用者選擇的是<span style="font-family: "Times New Roman", serif;">-O0</span>到<span style="font-family: "Times New Roman", serif;">-O3,</span>預設都會以<span style="font-family: "Times New Roman", serif;">-OSpace</span>編譯<span style="font-family: "Times New Roman", serif;">,</span>如果使用者選擇<span style="font-family: "Times New Roman", serif;">-OTime,</span>採用的優化原則也會有所不同 <span style="font-family: "Times New Roman", serif;">(</span>包含是否有 <span style="font-family: "Times New Roman", serif;">auto inline),</span>所對應出來的程式碼大小也會不同<span style="font-family: "Times New Roman", serif;">. </span>不過基本上<span style="font-family: "Times New Roman", serif;">,Thumb2</span>先天優勢就是屬於<span style="font-family: "Times New Roman", serif;">16/32bits</span>混合執行的模式<span style="font-family: "Times New Roman", serif;">,</span>也支援相對豐富的指令集<span style="font-family: "Times New Roman", serif;">(</span>不同版本的<span style="font-family: "Times New Roman", serif;">ARM Core Thumb2</span>指令集會有一些完整度的差異<span style="font-family: "Times New Roman", serif;">,</span>例如<span style="font-family: "Times New Roman", serif;">Cortex M3</span>只支援<span style="font-family: "Times New Roman", serif;">Thumb2 Subset.),</span>若非特別要求效能的區塊<span style="font-family: "Times New Roman", serif;">,</span>會是一個不錯的選擇<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此外<span style="font-family: "Times New Roman", serif;">,ARMv32</span>指令集固定為<span style="font-family: "Times New Roman", serif;">32bits</span>長度<span style="font-family: "Times New Roman", serif;">,</span>其中包含條件判斷<span style="font-family: "Times New Roman", serif;">,</span>操作碼<span style="font-family: "Times New Roman", serif;">(OP Code),</span>是否影響<span style="font-family: "Times New Roman", serif;">CPSR,</span>目標與操作暫存器編碼<span style="font-family: "Times New Roman", serif;">,</span>如下為一般<span style="font-family: "Times New Roman", serif;">ARMv32</span>指令集的格式 <span style="font-family: "Times New Roman", serif;">(</span>參考文件<span style="font-family: "Times New Roman", serif;">ARMv7-AR Architecture Reference Manual.pdf),</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" frame="HSIDES" rules="GROUPS" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 983px;"><colgroup><col width="129"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="12"></col><col width="14"></col><col width="10"></col><col width="11"></col><col width="12"></col><col width="10"></col></colgroup><colgroup><col width="0"></col><col width="12"></col><col width="12"></col><col width="12"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="12"></col><col width="11"></col><col width="6"></col><col width="7"></col><col width="5"></col><col width="4"></col><col width="4"></col><col width="5"></col><col width="5"></col><col width="5"></col><col width="5"></col><col width="5"></col></colgroup><colgroup><col width="217"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>ARM</strong></span></span><span style="font-size: xx-small;"><strong>指令集分類</strong></span></td><td colspan="33" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="607"><span style="font-size: xx-small;"><strong>位元</strong></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-size: xx-small;"><strong>指令集範例</strong></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>31</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>30</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>29</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>28</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>27</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>26</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>25</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>24</strong></span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>23</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>22</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>21</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>20</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>19</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>18</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>17</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>16</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>15</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>14</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>13</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>12</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>11</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>10</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>9</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>8</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>7</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>6</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>5</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>4</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>3</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>2</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>10</strong></span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="231"></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Data Processing<br />(Registers)</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="18"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op3</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AND,EOR,SUB,RSB,ADD,ADC,SBC,RSC,TST,TEQ,CMP,CMN,ORR,MOV,LSL,LSR,ASR,RRX,ROR,BIC,MVN</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Data Processing<br />(Register-shifted register)</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="12" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="230"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="18"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AND,EOR,SUB,RSB,ADD,ADC,SBC,RSC,TST,TEQ,CMP,CMN,ORR,LSL,LSR,ASR,ROR,BIC,MVN</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Data Processing<br />(Immediate)</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="16" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="266"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AND,EOR,SUB,ADR,RSB,ADD,ADR,ADC,SBC,RSC,TST,TEQ,CMP,CMN,ORR,MOV,BIC,MVN</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Multiply and multiply-accumulate</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="78"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="12" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="230"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">MUL,MLA,UMAAL,MLS,UMULL,UMLAL,SMULL,SMLAL</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Saturating addition and subtraction</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="36"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="12" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="230"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">QADD,QSUB,QDADD,QDSUB</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Halfword and multiply and multiply-accumulate</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="36"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="12" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="230"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SMLABB,SMLABT,SMLATB,SMLATT,SMLAWB,SMLAWT,SMULWB,SMULWT,SMLALBB,SMLALBT,SMLALTB,SMLALTT,SMULBB,SMULBT,SMULTB,SMULTT</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Extra load/store instructions</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="18"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STRH,LDRH,LDRD,LDRSB,STRD,LDRSH,</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Extra load/store instructions (unprivileged)</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rt</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="66"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="18"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STRHT,LDRHT,LDRSBT,LDRSHT</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Synchronization primitives</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="78"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="12" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="230"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SWP,SWPB,STREX,LDREX,STREXD,LDREXD,STREXB,LDREXB,STREXH,LDREXH,</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>MSR(immediate) and hints</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="108"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">NOP,YIELD,WFE,WFI,SEV,DBG,MSR</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Miscellaneous instructions</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="36"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">MRS,MSR,BX,CLZ,BXJ,BLX,BKPT,SMC</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/Store word and unsigned byte</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">A</span></span></td><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="11" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="192"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">B</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STR,STRT,LDR,LDRT,STRB,STRBT,LDRB,LDRBT</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Media instructions</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rd</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="66"></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">USAD8,USADA8,SBFX,BFC,BFI,UBFX</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Parallel addition and subtraction,signed</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="12" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="230"></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SADD16,SASX,SSAX,SSUB16,SADD8,SSUB8,QADD16,QASX,QSUB16,QADD8,QSUB8,SHADD16,SHASX,SHSAX,SHSUB16SHADD8,SHSUB8</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Parallel addition and subtraction,unsigned</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="12" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="230"></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">UADD16,UASX,USAX,USUB16,UADD8,USUB8,UQADD16,UQASX,UQSAX,UQSUB16,UQADD8,UQSUB8,UHADD16,UHASX,UHSAX,UHSUB16,UHADD8,UHSUB8</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Packing,unpacking,saturation, and reversal</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">A</span></span></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">PKH,SSAT,USAT,SXTAB16,SEL,SSAT16,SXTAB,SXTB,REV,SXTAH,SXTH,REV16,UXTAB16,UXTB16,USAT16,UXTAB,UXTB,RBIT,UXTAH,UXTH,REVSH</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Signed multiplies</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">A</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="66"></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SMLAD,SMUAD,SMLSD,SMUSD,SMLALD,SMLSLD,SMMLA,SMMUL,SMMLE</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Branch,branch with link, and block data transfer</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">R</span></span></td><td colspan="15" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="245"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STMDA,STMED,LDMDA,LDMFA,STM,STMIA,STMEA,LDMDB,LDMEA,STMIB,STMFA,LDMIB,LDMED,LDM,B,BL,BLX</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Supervisor call,and coprocessor instructions</strong></span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="76"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Cond.</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="7" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="120"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="66"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">coproc</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="34"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STC,STC2,LDC,LDC2,MCRR,MCRR2,MRRC,MRRC2,CDP,CDP2,MCR,MCR2,MRC,MRC2,SVC(previously SWI).</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Unconditional instructions</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td colspan="9" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="164"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="11" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="192"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SRS,RFE,BL,BLX,LDC,LDC2,STC,STC2,MCRR,MCRR2,MRRC,MRRC2,CDP,CDP2,MCR,MCR2,MRC,MRC2</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="129"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Miscellaneous instructions,memory hints, and Advanced SIMD instructions</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="color: red;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="14"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="140"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="148"></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="49"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="217"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">CPS,SETEND,PLI,PLD,PLDW,CLREX,DSB,DMB,ISB,</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM 32bits</span>的指令集<span style="font-family: "Times New Roman", serif;">,</span>前面<span style="font-family: "Times New Roman", serif;">4 bits,</span>為指令執行條件碼<span style="font-family: "Times New Roman", serif;">,</span>彙整如下供參考<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(</span>參考<span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0473b/CEGBHJCJ.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0473b/CEGBHJCJ.html</a></span></span> )</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 679px;"><colgroup><col width="58"></col><col width="288"></col><col width="302"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">Cond.</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288">意義</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302">對應<span style="font-family: "Times New Roman", serif;">CPSR</span>中的標誌值</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b0000</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">EQ(Equal)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">Z set</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b0001</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">NE(Not equal)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">Z clear</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b0010</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">CS or HS<br />(Higher or same (unsigned >= ))</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">C set</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b0011</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">CC or LO<br />(Lower (unsigned < ))</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">C clear</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b0100</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">MI(Negative)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">N set</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b0101</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">PL(Positive or zero)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">N clear</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b0110</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">VS(Overflow)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">V set</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b0111</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">VC(No overflow)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">V clear</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b1000</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">HI(Higher (unsigned >))</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">C set and Z clear</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b1001</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">LS(Lower or same (unsigned <=))</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">C clear or Z set</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b1010</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">GE(Signed >=)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">N and V the same</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b1011</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">LT(Signed <)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">N and V differ</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b1100</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">GT(Signed >)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">Z clear, N and V the same</span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b1101</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">LE(Signed <=)</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"><span style="font-family: "Times New Roman", serif;">Z set, N and V differ</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b1110</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">AL</span>無條件執行</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;">b1111</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="288"><span style="font-family: "Times New Roman", serif;">NV</span>該指令不執行</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="302"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<img align="BOTTOM" alt="" border="0" height="2" src="http://ccckmit.wikidot.com/local--resized-images/as:arm/ARM_format.jpg/medium.jpg" style="background-color: #f3f3f3; border-radius: 3px; border: 1px solid rgb(221, 221, 221); padding: 5px;" width="2" /></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
不像是<span style="font-family: "Times New Roman", serif;">ARMv32</span>指令集固定都為<span style="font-family: "Times New Roman", serif;">32bits,Thumb</span>指令集固定為<span style="font-family: "Times New Roman", serif;">16bits,</span>而<span style="font-family: "Times New Roman", serif;">Thumb2</span>則是同時提供了<span style="font-family: "Times New Roman", serif;">16bits</span>與<span style="font-family: "Times New Roman", serif;">32bits</span>的指令集格式<span style="font-family: "Times New Roman", serif;">,</span>並可提供優於<span style="font-family: "Times New Roman", serif;">Thumb</span>指令集的執行效能<span style="font-family: "Times New Roman", serif;">,</span>程式碼編譯後<span style="font-family: "Times New Roman", serif;">,</span>如果<span style="font-family: "Times New Roman", serif;">15-11bits</span>這<span style="font-family: "Times New Roman", serif;">5</span>個<span style="font-family: "Times New Roman", serif;">bits</span>為<span style="font-family: "Times New Roman", serif;">0b11101,0b11110</span>或<span style="font-family: "Times New Roman", serif;">0b11111</span>就表示是<span style="font-family: "Times New Roman", serif;">32bits Thumb2</span>指令集<span style="font-family: "Times New Roman", serif;">,</span>如下為一般<span style="font-family: "Times New Roman", serif;">Thumb/Thumb2</span>指令集的格式 <span style="font-family: "Times New Roman", serif;">(</span>參考文件<span style="font-family: "Times New Roman", serif;">ARMv7-AR Architecture Reference Manual.pdf),</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" frame="ABOVE" rules="GROUPS" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 983px;"><colgroup><col width="183"></col><col width="10"></col><col width="13"></col><col width="10"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="6"></col><col width="3"></col><col width="11"></col><col width="6"></col><col width="4"></col><col width="7"></col><col width="6"></col><col width="6"></col><col width="7"></col><col width="4"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="11"></col><col width="12"></col><col width="10"></col><col width="4"></col><col width="5"></col><col width="0"></col><col width="5"></col><col width="0"></col><col width="4"></col><col width="4"></col><col width="5"></col><col width="4"></col><col width="4"></col><col width="4"></col><col width="4"></col></colgroup><colgroup><col width="220"></col></colgroup><tbody>
<tr valign="TOP"><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Thumb/Thumb2</strong></span></span><span style="font-size: xx-small;"><strong>指令集分類</strong></span></td><td colspan="34" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="550"><span style="font-size: xx-small;"><strong>位元</strong></span></td><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-size: xx-small;"><strong>指令集範例</strong></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td colspan="16" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="278"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1st 16bits</strong></span></span></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>2nd 16bits</strong></span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>15</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>14</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>13</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>12</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>11</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>10</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>9</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>8</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>7</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>6</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>5</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>4</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>3</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>2</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>15</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>14</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>13</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>12</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>11</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>10</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>9</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>8</strong></span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>7</strong></span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>6</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>5</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>4</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>3</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>2</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>10</strong></span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="234"></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Shift(immediate),add,subtract,move and compare</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="89"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Opcode</strong></span></span></td><td colspan="9" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">LSL,LSR,ASR,ADD,SUB,MOV,CMP</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Data Processing</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Opcode</span></span></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="86"></td><td colspan="18" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AND,EOR,LSL,LSR,ASR,ADC,SBC,ROR,TST,RSB,CMP,CMN,ORR,MUL,BIC,MVN</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Special data instructions and branch and exchange</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="56"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Opcode</span></span></td><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="86"></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ADD,CMP,MOV,BX,BLX</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/store single data item</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="48"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">opB</span></span></td><td colspan="9" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"></td><td colspan="18" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STR,STRH,STRB,LDRSB,LDR,LDRH,LDRB,LDRSH</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/store single data item</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="48"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">opB</span></span></td><td colspan="9" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STR,LDR,</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/store single data item</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="48"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">opB</span></span></td><td colspan="9" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"></td><td colspan="18" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STRB,LDRB</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/store single data item</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="48"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">opB</span></span></td><td colspan="9" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STRH,LDRH</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/store single data item</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="48"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">opB</span></span></td><td colspan="9" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="136"></td><td colspan="18" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STR,LDR</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Miscellaneous 16bits instructions</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="7" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="112"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Opcode</span></span></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SETEND,CPS,ADD,SUB,CBNZ,SXTH,SXTB,UXTH,UXTB,CBNZ,CBZ,PUSH,REV,REV16,REVSH,POP,BKPT,</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>If-then and hints</strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">opA</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">opB</span></span></td><td colspan="18" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">IT,NOP,YIELD,WFE,WFI,SEV</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Conditional branch and supervisor call</strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="61"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Opcode</span></span></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="123"></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">B,SVC(previously SWI)</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Data processing(modified immediate)</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">S</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="52"></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rd</span></span></td><td colspan="9" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AND,TST,BIC,ORR,MOV,ORN,MVN,EOR,TEQ,ADD,CMN,ADC,SBC,SUB,CMP,RSB</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Data processing(plain binary immediate)</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="17" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="242"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ADD,ADR,MOV,SUB,ADR,MOVT,SSAT,SSAT16,SBFX,BFI,BFC,USAT,USAT16,UBFX</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Branched and miscellaneous control</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span></td><td bgcolor="#9999ff" colspan="7" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="108"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="52"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="9" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">B,MSR,BXJ,SUBS,SMC(previously SMI),BL,BLX</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Change Processor State ,and hints</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td colspan="9" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">CPS,NOP,YIELD,WFE,WFI,SEV,DBG</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Miscellaneous control instructions</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="52"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">ENTERX,LEAVEX,CLREX,DSB,DMB,ISB</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/Store Multiple</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">L</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="18" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="263"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SRS,RFE,STM,STMIA,STMEA,LDM,LDMIA,LDMFD,POP,STMDB,STMFD,PUSH,LDMDB,LDMEA,SRS,RFE</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load/Store dual,Load/Store exclusive,table branch</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="22"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="9" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="52"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op3</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STREX,LDREX,STRD,LDRD,STREXB,STREXH,STREXD,TBB,TBH,LDREXB,LDREXH,LDREXD</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load word</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">LDR,LDRT</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load halfword, memory hints</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rt</span></span></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">LDRH,LDRHT,LDRSH,LDRSHT,PLD,PLDW,</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Load byte, memory hints</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="24"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rt</span></span></td><td colspan="8" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="6" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">LDRB,LDRBT,LDRSB,LDRSBT,PLD,PLDW,PLI</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Store single data item</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="41"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="8" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="95"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="75"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STRB,STRBT,STRH,STRHT,STRT,STR</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Data processing(shifted register)</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>0</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">S</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rd</span></span></td><td colspan="9" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="107"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">AND,TST,BIC,ORR,MOV,ORN,MVN,EOR,TEQ,PKH,ADD,CMN,ADC,SBC,SUB,CMP,RSB</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Data processing(register)</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="58"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="52"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">LSL,LSR,ASR,ROR,SXTAH,SXTH,UXTAH,UXTH,SXTAB16,SXTB16,UXTAB16,UXTB16,SXTAB,SXTB,UXTAB,UXTB,</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Parallel addition and subtraction,signed</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="8"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="19"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SADD16,SASX,SSAX,SSUB16,SADD8,SSUB8,QADD16,QASX,QSUB16,QADD8,QSUB8,SHADD16,SHASX,SHSUB16,SHADD8,SHSUB8</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Parallel addition and subtraction,unsigned</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="8"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="19"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">UADD16,UASX,USAX,USUB16,UADD8,USUB8,UQADD16,UQASX,UQSAX,UQSUB16,UQADD8,UQSUB8,UHADD16,UHASX,UHSAX,UHSUB16,UHADD8,UHSUB8</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Miscellaneous operations</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="22"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="8"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="19"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">QADD,QDADD,QSUB,QDSUB,REV,REV16,RBIT,REVSH,SEL,CLZ</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Multiply,multiply accumulate,and absolute difference</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Ra</span></span></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="8"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td colspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="19"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">MLA,MUL,MLS,SMLABB,SMLABT,SMLATB,SMLATT,SMULBB,SMULBT,SMULTB,SMULTT,SMLAD,SMUAD,SMLAWB,SMLAWT,SMULWB,SMULWT,SMLSD,SMUSD,SMMLA,SMMUL,SMMLS,USAD8,USADA8</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Long multiply,long multiply accumulate,and divide</strong></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">0</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="3" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="38"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"></td><td colspan="9" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"></td><td colspan="5" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="52"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op2</span></span></td><td colspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">SMULL,SDIV,UMULL,UDIV,SMLAL,SMLALBB,SMLALBT,SMLALTB,SMLALTT,SMLALD,SMLSLD,UMLAL,UMAAL</span></span></td></tr>
</tbody><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>Coprocessor instructions</strong></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="color: #b80047;"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;"><strong>1</strong></span></span></span></td><td bgcolor="#9999ff" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">1</span></span></td><td bgcolor="#9999ff" colspan="6" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="88"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op1</span></span></td><td bgcolor="#9999ff" colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="54"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">Rn</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="72"></td><td colspan="5" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="63"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">coproc</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="37"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">op</span></span></td><td colspan="4" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="45"></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-size: xx-small;">STC,STC2,LDC,LDC2,MCRR,MCRR2,MRRC,MRRC2,CDP,CDP2,MCR,MCR2,MRC,MRC2</span></span></td></tr>
</tbody><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="183"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="13"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="3"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="6"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="11"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="12"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="10"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="7"></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="8"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="5"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="4"></td><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="234"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來<span style="font-family: "Times New Roman", serif;">,</span>我們把<span style="font-family: "Times New Roman", serif;">ARM</span>處理器的一些基礎特徵<span style="font-family: "Times New Roman", serif;">,</span>做一些介紹</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>A,</strong></span><span style="font-size: small;"><strong> </strong></span></span><span style="font-size: small;"><strong>有關</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>ARM </strong></span></span><span style="font-size: small;"><strong>新增的</strong></span><span style="font-size: small;"><strong>指令集簡要介紹</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有關不同版本的<span style="font-family: "Times New Roman", serif;">ARM</span>核心支援的指令集<span style="font-family: "Times New Roman", serif;">,</span>建議可以參考<span style="font-family: "Times New Roman", serif;">ARMR and ThumbR-2 Instruction Set Quick Reference Card(<span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf</a></span></span> ),</span>在這主要只針對部分筆者認為值得介紹的加以說明</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 995px;"><colgroup><col width="117"></col><col width="855"></col></colgroup><tbody>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "Times New Roman", serif;">ARMv4</span>新增</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="855"><span style="font-family: "Times New Roman", serif;">Thumb 16bits</span>指令集</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "Times New Roman", serif;">ARMv5</span>新增</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="855"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">VFPv2</span></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">Jazelle</span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">BLX:</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援透過</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">Link Register</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">的指令集狀態轉移</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">Branch</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">指令</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">BRK:</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援中斷</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">(Break)</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">指令</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">CLZ:</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">零</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">計數</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">指令</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">可</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">計</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">算最高</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">位</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">與</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">第一</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">個</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">1</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">之</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">間</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">零的</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">個數</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">如果</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">暫存器中全為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">0,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">則結</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">果</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">為</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;"> </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">32,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">如果</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">設</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">置</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">把</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">bit 31</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">設定</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">1,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">則結</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">果</span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">為</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">0,</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">對</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">MultiMedia Codec</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">優化很有助益</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">.</span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">其他像是</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">QADD</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">、</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">QSUB</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">、</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">QDADD </span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">和 </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">QDSUB(</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">有符号加法、减法,加倍加法,加倍减法</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">), ,SMULxy,SMLAxy,SMULWy,SMLAWy,SMLALxy(</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">乘法指令</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">.),</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">都是在</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">ARMv5</span></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">的核心中加入</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">.</span></span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "Times New Roman", serif;">ARMv6</span>新增</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="855"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">Thumb2</span></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">Trustzone</span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">SIMD</span></span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "Times New Roman", serif;">ARMv7-A/R</span>新增</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="855"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">VFPv3</span></span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">NEON Advanced SIMD</span></span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">ThumbEE</span></span></span></div>
</td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "Times New Roman", serif;">ARMv7-M</span>新增<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(For Low-Cost)</span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="855">不支援<span style="font-family: "Times New Roman", serif;">ARM</span>指令集<span style="font-family: "Times New Roman", serif;">,</span>只支援<span style="font-family: "Times New Roman", serif;">Thumb2 16/32bits</span>指令集<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(</span>支援最多<span style="font-family: "Times New Roman", serif;">240</span>個中斷的集成式<span style="font-family: "Times New Roman", serif;">NVIC</span>中斷控制器<span style="font-family: "Times New Roman", serif;">)</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "Times New Roman", serif;">SVC</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="855">在新的<span style="font-family: "Times New Roman", serif;">ARM</span>處理器中<span style="font-family: "Times New Roman", serif;">,SWI</span>的指令被改為<span style="font-family: "Times New Roman", serif;">SVC,</span>雖然對應到的指令機械碼還是一樣<span style="font-family: "Times New Roman", serif;">(</span>例如<span style="font-family: "Times New Roman", serif;">EFxxxxxx),</span>但命名的改變<span style="font-family: "Times New Roman", serif;">,</span>對應到的是新的處理器對<span style="font-family: "Times New Roman", serif;">SWI(SVC)</span>行為的進一步改善<span style="font-family: "Times New Roman", serif;">.</span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="117"><span style="font-family: "Times New Roman", serif;">LDREX</span>與<span style="font-family: "Times New Roman", serif;">STREX</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="855">這是在<span style="font-family: "Times New Roman", serif;">ARMv6</span>之後新加入的指令<span style="font-family: "Times New Roman", serif;">,</span>用來進行處理器層級的 <span style="font-family: "Times New Roman", serif;">Register/Memory Exclusive Access </span>確保<span style="font-family: "Times New Roman", serif;">,LDREX</span>跟<span style="font-family: "Times New Roman", serif;">STREX</span>是成對的使用<span style="font-family: "Times New Roman", serif;">.</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下例子<span style="font-family: "Times New Roman", serif;">,</span>使用者透過<span style="font-family: "Times New Roman", serif;">LDREX</span>讀取一個記憶體的值<span style="font-family: "Times New Roman", serif;">,</span>如果在執行<span style="font-family: "Times New Roman", serif;">STREX</span>前<span style="font-family: "Times New Roman", serif;">,</span>該記憶體中的值被修改了<span style="font-family: "Times New Roman", serif;">,STREX</span>動作會失敗且第一個暫存器<span style="font-family: "Times New Roman", serif;">R0</span>的值會不為<span style="font-family: "Times New Roman", serif;">0 (non-exclusive by this CPU),</span>反之<span style="font-family: "Times New Roman", serif;">,</span>若該值沒有被更動到<span style="font-family: "Times New Roman", serif;">,STREX</span>動作會成功且<span style="font-family: "Times New Roman", serif;">R0</span>為<span style="font-family: "Times New Roman", serif;">0(exclusive access by this CPU).</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
這個處理器層級的<span style="font-family: "Times New Roman", serif;">Exclusive</span>指令<span style="font-family: "Times New Roman", serif;">,</span>很適合用在<span style="font-family: "Times New Roman", serif;">Multi-Task</span>多工的環境或是多核心的環境中<span style="font-family: "Times New Roman", serif;">.</span>目前<span style="font-family: "Times New Roman", serif;">ARM</span>版本的<span style="font-family: "Times New Roman", serif;">Linux Kernel Spin Lock</span>也是用此指令實作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">try</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">LDREX r0, [LockAddr] ; load the lock value</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">CMP r0, #0 ; is the lock free?</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">STREXEQ r0, r1, [LockAddr] ; try and claim the lock</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">CMPEQ r0, #0 ; did this succeed?</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BNE try ; no – try again</span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>B,</strong></span></span><span style="font-size: small;"><strong>使用</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Branch </strong></span></span><span style="font-size: small;"><strong>指令在不同指令集中切換</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以參考文件 <span style="font-family: "Times New Roman", serif;"><strong>RealView® Compilation Tools Developer Guide</strong> </span>中 “<span style="font-family: "Times New Roman", serif;"><strong>Chapter 5. Interworking ARM and Thumb”</strong> </span>的例子<span style="font-family: "Times New Roman", serif;">,</span>如下程式碼</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PRESERVE8 ;Preserves eight-byte alignment of the stack</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">AREA TestCode,CODE,READONLY ; Name this block of code.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ENTRY ; Mark first instruction to call.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">; </span>程式進入點</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">start</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ADR R0, ThumbProg ; Generate branch target address and set bit 0, hence arrive at target in Thumb state.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ORR R0,R0,#1 ;</span>等於是跳到目標位址<span style="font-family: "Times New Roman", serif;">ThumbProg+1</span>的位址<span style="font-family: "Times New Roman", serif;">,</span>再透過<span style="font-family: "Times New Roman", serif;">BX</span>指令引發處理器指令集轉態為<span style="font-family: "Times New Roman", serif;">Thumb Mode</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BX R0 ; Branch exchange to ThumbProg.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">;ThumbCode</span>區域</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">THUMB ; Subsequent instructions are Thumb code.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ThumbProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOVS R2, #2 ; Load R2 with value 2.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOVS R3, #3 ; Load R3 with value 3.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ADDS R2, R2, R3 ; R2 = R2 + R3</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ADR R0, ARMProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BX R0 ; Branch exchange to ARMProg.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">;Thumb Code</span>為<span style="font-family: "Times New Roman", serif;">2bytes,ARMv32 Code</span>為<span style="font-family: "Times New Roman", serif;">4bytes alignment</span>取值<span style="font-family: "Times New Roman", serif;">,</span>編譯器會在這補上<span style="font-family: "Times New Roman", serif;">2bytes 0x00,</span>以便讓後續<span style="font-family: "Times New Roman", serif;">ARMv32 Code</span>正常執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">;ARMCode</span>區域</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM ; Subsequent instructions are ARM code.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARMProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOV R4, #4</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOV R5, #5</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ADD R4, R4, R5</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">; </span>結束程式<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">stop MOV R0, #0x18 ; angel_SWIreason_ReportException</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">LDR R1, =0x20026 ; ADP_Stopped_ApplicationExit</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">SWI 0x123456 ; ARM semihosting</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">END ; Mark end of this file.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過如下指令編譯與連結</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">armasm –debug –apcs=/interwork ARMThumbMixedCode.s</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">armlink ARMThumbMixedCode.o -o ARMThumbMixedCode.elf</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
把編譯後的<span style="font-family: "Times New Roman", serif;">ARMThumbMixedCode.elf</span>放到<span style="font-family: "Times New Roman", serif;">ARM</span>處理器執行<span style="font-family: "Times New Roman", serif;">,</span>從<span style="font-family: "Times New Roman", serif;">CPSR</span>來看<span style="font-family: "Times New Roman", serif;">,</span>一開始運作時處理器指令集是在<span style="font-family: "Times New Roman", serif;">ARM Mode(CPSR</span>的<span style="font-family: "Times New Roman", serif;">T bit</span>為<span style="font-family: "Times New Roman", serif;">0),</span>隨後透過</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ADR R0, ThumbProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ORR R0,R0,#1</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BX R0</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">R0</span>儲存<span style="font-family: "Times New Roman", serif;">Thumb Code</span>所在目標位址 <span style="font-family: "Times New Roman", serif;">OR </span>最小一個<span style="font-family: "Times New Roman", serif;">Bit</span>為<span style="font-family: "Times New Roman", serif;">1,</span>透過<span style="font-family: "Times New Roman", serif;">BX</span>轉態跳到<span style="font-family: "Times New Roman", serif;">Thumb Mode(CPSR</span>的<span style="font-family: "Times New Roman", serif;">T bit</span>為<span style="font-family: "Times New Roman", serif;">1)</span>執行<span style="font-family: "Times New Roman", serif;">ThumbProg</span>之後的程式碼<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">Thumb Mode</span>執行的最後再透過</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ADR R0, ARMProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BX R0</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">R0</span>儲存<span style="font-family: "Times New Roman", serif;">ARM Code</span>所在位址<span style="font-family: "Times New Roman", serif;">,</span>並直接透過<span style="font-family: "Times New Roman", serif;">BX</span>轉態跳到<span style="font-family: "Times New Roman", serif;">ARM Mode(CPSR</span>的<span style="font-family: "Times New Roman", serif;">T bit</span>為<span style="font-family: "Times New Roman", serif;">0),</span>繼續執行<span style="font-family: "Times New Roman", serif;">ARMProg</span>之後的<span style="font-family: "Times New Roman", serif;">ARM</span>程式碼<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下列出不同的<span style="font-family: "Times New Roman", serif;">Branch</span>指令所能跳躍的範圍 <span style="font-family: "Times New Roman", serif;">(</span>一般而言<span style="font-family: "Times New Roman", serif;">ARM</span>最大為<span style="font-family: "Times New Roman", serif;">32MB,Thumb2</span>為<span style="font-family: "Times New Roman", serif;">16MB,Thumb</span>為<span style="font-family: "Times New Roman", serif;">4MB).</span></div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 100%px;"><colgroup><col width="85*"></col><col width="85*"></col><col width="85*"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-size: x-small;">指令</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-size: x-small;">範圍</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(Thumb2 16/32bits)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-size: x-small;">範圍</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(ARM 32bits)</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Italic, serif;"><span style="font-size: x-small;"><em>B (</em><span style="font-family: Times-Roman, serif;">Branch to target address)</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">+/–16MB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">+/–32MB</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Italic, serif;"><span style="font-size: x-small;"><em>CBNZ, CBZ(</em><span style="font-family: Times-Roman, serif;">Compare and Branch on Nonzero, Compare and Branch on Zero</span><em>)</em></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">0-126B</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">X</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Italic, serif;"><span style="font-size: x-small;"><em>BL, BLX (immediate) (</em><span style="font-family: Times-Roman, serif;">Call a subroutine ,Call a subroutine, change instruction set</span><span style="font-family: Times-Roman, serif;">)</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">+/–16MB</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">+/–32MB</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Italic, serif;"><span style="font-size: x-small;"><em>BLX (register) (</em><span style="font-family: Times-Roman, serif;">Call a subroutine, optionally change instruction set</span><em>)</em></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">Any</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">Any</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Italic, serif;"><span style="font-size: x-small;"><em>BX (</em><span style="font-family: Times-Roman, serif;">Branch to target address, change instruction set)</span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">Any</span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">Any</span></span></td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;"><span style="font-family: Times-Italic, serif;"><em>BXJ </em></span>(Change to Jazelle state)</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">–</span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">–</span></span></td></tr>
<tr valign="TOP"><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Italic, serif;"><span style="font-size: x-small;"><em>TBB, TBH (</em><span style="font-family: Times-Roman, serif;">Table Branch (byte offsets) and Table Branch (halfword offsets)</span><em>)</em></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: Times-Roman, serif;"><span style="font-size: x-small;">0-510B and</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><span style="font-family: Times-Roman, serif;">0-131070B</span></span></span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="33%"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">X</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(Reference:ARMv7-AR Architecture Reference Manual)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>C,Veneer-</strong></span></span><span style="font-size: small;"><strong>用來支援跨不同</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>Obj</strong></span></span><span style="font-size: small;"><strong>檔案時的</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>ARM</strong></span></span><span style="font-size: small;"><strong>指令集轉換</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>.</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由前面的例子我們可以知道<span style="font-family: "Times New Roman", serif;">,ARM<->Thumb(2)</span>的轉態動作如果是在同一個<span style="font-family: "Times New Roman", serif;">Source Code</span>檔案<span style="font-family: "Times New Roman", serif;">(Obj</span>檔案<span style="font-family: "Times New Roman", serif;">)</span>中時<span style="font-family: "Times New Roman", serif;">,</span>轉態的動作其實就是直接在程式碼中執行與動作<span style="font-family: "Times New Roman", serif;">,</span>但如果所發生的<span style="font-family: "Times New Roman", serif;">ARM<->Thumb(2)</span>的轉態行為是發生在一個以上不同的<span style="font-family: "Times New Roman", serif;">Source Code</span>之間的呼叫<span style="font-family: "Times New Roman", serif;">,</span>就會牽涉到每個<span style="font-family: "Times New Roman", serif;">Obj</span>檔案在編譯時的參數差異<span style="font-family: "Times New Roman", serif;">,</span>有關跨不同<span style="font-family: "Times New Roman", serif;">Obj</span>檔案間判別是部是需要在兩個<span style="font-family: "Times New Roman", serif;">Obj</span>檔案的函式中支援轉態的動作<span style="font-family: "Times New Roman", serif;">,</span>就會變成在<span style="font-family: "Times New Roman", serif;">ARM Link</span>最後連結的動作中<span style="font-family: "Times New Roman", serif;">,</span>依據跨檔案互相呼叫的雙方是不是在同一個指令集下<span style="font-family: "Times New Roman", serif;">,</span>如果不是就會透過加入<span style="font-family: "Times New Roman", serif;">Veneer</span>的嵌入碼<span style="font-family: "Times New Roman", serif;">,</span>確保最後透過<span style="font-family: "Times New Roman", serif;">ARMLink</span>連結的執行檔<span style="font-family: "Times New Roman", serif;">,</span>可以支援所連結不同來源的<span style="font-family: "Times New Roman", serif;">Obj</span>檔中所包含的指令集差異<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以產生一個<span style="font-family: "Times New Roman", serif;">arm.s</span>檔案<span style="font-family: "Times New Roman", serif;">,</span>內容如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">PRESERVE8</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">AREA Arm,CODE,READONLY ; Name this block of code.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">IMPORT ThumbProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ENTRY ; Mark 1st instruction to call.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARMProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOV R0,#1 ; Set R0 to show in ARM code.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BL ThumbProg ; Call Thumb subroutine.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOV R2,#3 ; Set R2 to show returned to ARM.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">; Terminate execution.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOV R0, #0x18 ; angel_SWIreason_ReportException</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">LDR R1, =0x20026 ; ADP_Stopped_ApplicationExit</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">SVC 0x123456 ; ARM semihosting (formerly SWI)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">END</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並產生一個 <span style="font-family: "Times New Roman", serif;">thumb.s,</span>內容如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">AREA Thumb,CODE,READONLY ; Name this block of code.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">THUMB ; Subsequent instructions are Thumb.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">EXPORT ThumbProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ThumbProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOVS R1, #2 ; Set R1 to show reached Thumb code.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BX lr ; Return to the ARM function.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">END ; Mark end of this file.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
執行如下編譯<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">armasm –debug –apcs=/interwork arm.s</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">armasm –thumb –debug –apcs=/interwork thumb.s</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">armlink arm.o thumb.o -o arm_thumb_veneer.elf</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於是跨不同的<span style="font-family: "Times New Roman", serif;">Obj</span>檔案<span style="font-family: "Times New Roman", serif;">,</span>不同於在同一個<span style="font-family: "Times New Roman", serif;">Obj</span>檔案中<span style="font-family: "Times New Roman", serif;">,</span>我們需要把<span style="font-family: "Times New Roman", serif;">Thumb Code</span>函式進入點的<span style="font-family: "Times New Roman", serif;">Bit0,</span>設定為<span style="font-family: "Times New Roman", serif;">1</span>再透過<span style="font-family: "Times New Roman", serif;">BX</span>指令跳躍過去讓<span style="font-family: "Times New Roman", serif;">ARMv32</span>可以轉程<span style="font-family: "Times New Roman", serif;">Thumb Code</span>的指令集<span style="font-family: "Times New Roman", serif;">,</span>在上述的例子中<span style="font-family: "Times New Roman", serif;">,</span>我們可以直接呼叫<span style="font-family: "Times New Roman", serif;">ThumbProg,</span>透過<span style="font-family: "Times New Roman", serif;">Veneer</span>機制達成由<span style="font-family: "Times New Roman", serif;">ARMv32</span>轉態為<span style="font-family: "Times New Roman", serif;">Thumb Code</span>的目的<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下<span style="font-family: "Times New Roman", serif;">,</span>我們透過反組譯<span style="font-family: "Times New Roman", serif;">arm_thumb_veneer.elf</span>確認<span style="font-family: "Times New Roman", serif;">Veneer</span>機制的作用<span style="font-family: "Times New Roman", serif;">,</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">$a</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Arm</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x00008000: e3a00001 …. MOV r0,#1</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x00008004: eb000004 …. BL $Ven$AT$I$$ThumbProg ; 0x801c</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x00008008: e3a02003 . .. MOV r2,#3</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x0000800c: e3a00018 …. MOV r0,#0x18</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x00008010: e59f1000 …. LDR r1,[pc,#0] ; [0x8018] = 0x20026</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x00008014: ef123456 V4.. SVC #0x123456 ; formerly SWI</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">$d</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x00008018: 00020026 &… DCD 131110</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>$a</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>$Ven$AT$I$$ThumbProg</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>0x0000801c: e28fc001 …. ADR r12,{pc}+9 ; 0x8025</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>0x00008020: e12fff1c ../. BX r12</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">$t</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Thumb</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ThumbProg</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x00008024: 2102 .! MOVS r1,#2</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0x00008026: 4770 pG BX lr</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以看到在<span style="font-family: "Times New Roman", serif;">ARM Mode</span>時<span style="font-family: "Times New Roman", serif;">,</span>會在位址 <span style="font-family: "Times New Roman", serif;">0x00008004</span>透過<span style="font-family: "Times New Roman", serif;">BL</span>跳到位址<span style="font-family: "Times New Roman", serif;">0x0000801c</span>執行<span style="font-family: "Times New Roman", serif;">Veneer Code,</span>如同我們在同一個<span style="font-family: "Times New Roman", serif;">Obj</span>檔案中所做的<span style="font-family: "Times New Roman", serif;">Bit0</span>設定為<span style="font-family: "Times New Roman", serif;">1</span>的動作<span style="font-family: "Times New Roman", serif;">,</span>在所產生的<span style="font-family: "Times New Roman", serif;">Veneer Code</span>中會設定<span style="font-family: "Times New Roman", serif;">R12</span>暫存器指到<span style="font-family: "Times New Roman", serif;">0x00008025,</span>再透過<span style="font-family: "Times New Roman", serif;">BX</span>指令轉態執行<span style="font-family: "Times New Roman", serif;">0x00008024</span>中的<span style="font-family: "Times New Roman", serif;">Thumb Code.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Veneer</span>是由<span style="font-family: "Times New Roman", serif;">ARM Linker</span>根據最後連結成執行檔的階段<span style="font-family: "Times New Roman", serif;">,</span>判斷程式碼是否有跨<span style="font-family: "Times New Roman", serif;">Obj</span>間<span style="font-family: "Times New Roman", serif;">ARM</span>與<span style="font-family: "Times New Roman", serif;">Thumb Code</span>互相呼叫的需求<span style="font-family: "Times New Roman", serif;">,</span>或是<span style="font-family: "Times New Roman", serif;">ARM/Thumb/Thumb2</span>彼此呼叫超過<span style="font-family: "Times New Roman", serif;">Branch</span>上限範圍時<span style="font-family: "Times New Roman", serif;">,</span>就會自動產生<span style="font-family: "Times New Roman", serif;">,</span>可參考如下分類</div>
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 983px;"><colgroup><col width="243"></col><col width="718"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="243"><span style="font-family: "Times New Roman", serif;">Veneer</span>類型</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="718">說明</td></tr>
<tr valign="TOP"><td height="58" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="243"><span style="font-family: "Times New Roman", serif;">ARM/Thumb(2)</span>之間呼叫</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="718">在跨<span style="font-family: "Times New Roman", serif;">Obj</span>檔案的<span style="font-family: "Times New Roman", serif;">ARM<->Thumb</span>與<span style="font-family: "Times New Roman", serif;">ARM<->Thumb2</span>彼此呼叫時<span style="font-family: "Times New Roman", serif;">,</span>需要透過<span style="font-family: "Times New Roman", serif;">Veneer</span>轉態</td></tr>
<tr class="alt" valign="TOP"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="243">超過<span style="font-family: "Times New Roman", serif;">ARM/Thumb/Thumb2</span>的<span style="font-family: "Times New Roman", serif;">Branch</span>範圍</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="718">當<span style="font-family: "Times New Roman", serif;">ARM<->ARM </span>呼叫超過<span style="font-family: "Times New Roman", serif;">32MB.<br />Thumb2<->Thumb2</span>呼叫超過<span style="font-family: "Times New Roman", serif;">16MB</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Thumb<->Thumb</span>呼叫超過<span style="font-family: "Times New Roman", serif;">4MB.</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
就會需要透過<span style="font-family: "Times New Roman", serif;">Veneer Code,</span>協助完成呼叫流程<span style="font-family: "Times New Roman", serif;">.</span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>D, CPSR (Current Program Status Register)</strong></span></span><span style="font-size: small;"><strong>與 </strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>SPSR (Saved Program Status Register)</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
程式狀態暫存器 <span style="font-family: "Times New Roman", serif;">PSR(Program Status Register),</span>是用來紀錄程序狀態之用<span style="font-family: "Times New Roman", serif;">,</span>包括反映出目前所處的處理器模式<span style="font-family: "Times New Roman", serif;">,</span>指令集狀態<span style="font-family: "Times New Roman", serif;">,</span>以及反應出條件<span style="font-family: "Times New Roman", serif;">(Cond.)</span>執行指令判斷執行的依據<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉個例子來說<span style="font-family: "Times New Roman", serif;">,</span>當我們從<span style="font-family: "Times New Roman", serif;">CPSR</span>的<span style="font-family: "Times New Roman", serif;">4-0bits</span>取出值為<span style="font-family: "Times New Roman", serif;">b10111</span>就可以知道目前所在的<span style="font-family: "Times New Roman", serif;">Exception Handler,</span>是發生了<span style="font-family: "Times New Roman", serif;">Abort,</span>之後再判斷<span style="font-family: "Times New Roman", serif;">SPSR</span>的<span style="font-family: "Times New Roman", serif;">4-0bits,</span>若為<span style="font-family: "Times New Roman", serif;">b10011(SVC Mode)</span>或<span style="font-family: "Times New Roman", serif;">b10000(User Mode),</span>就可以知道在觸發這個<span style="font-family: "Times New Roman", serif;">Abort</span>前<span style="font-family: "Times New Roman", serif;">,</span>處理器是在執行哪一個模式下的程式碼<span style="font-family: "Times New Roman", serif;">,</span>再者<span style="font-family: "Times New Roman", serif;">,</span>如果擔心有因為<span style="font-family: "Times New Roman", serif;">Exception Handle</span>設計不當導致的<span style="font-family: "Times New Roman", serif;">Abort</span>重入問題<span style="font-family: "Times New Roman", serif;">,</span>也可以透過<span style="font-family: "Times New Roman", serif;">CPSR/SPSR</span>前後模式比對<span style="font-family: "Times New Roman", serif;">,</span>知道是不是<span style="font-family: "Times New Roman", serif;">Abort</span>重入<span style="font-family: "Times New Roman", serif;">,</span>可以鎖定潛在的系統問題加以解決<span style="font-family: "Times New Roman", serif;">. </span>如下簡述每個欄位的意義</div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 913px;"><colgroup><col width="100"></col><col width="161"></col><col width="638"></col></colgroup><tbody>
<tr valign="TOP"><td height="23" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">位元</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161">功能</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638">說明</td></tr>
<tr class="alt" valign="TOP"><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">4-0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">Mode[4:0]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Mode Bits</span>模式位元<span style="font-family: "Times New Roman", serif;"><br />b10000(0x0010) -User Mode<br />b10001(0x0011)- FIQ Mode<br />b10010(0x0012)-IRQ Mode<br />b10011(0x0013)-Supervisor Mode<br />b10111(0x0017)-Abort Mode</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">b11011(0x001b)-Undefined Mode<br />b11111(0x001F)-System Mode</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="text-decoration-line: underline;"><strong>b10110(0x0016)-Secure Monitor</strong></span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">5</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">T</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Thumb state bit</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0=ARM</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1=Thumb</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="34" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">6</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">F</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">FIQ Disable</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1=</span>禁止</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0=</span>允許</div>
</td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">7</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">I</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">IRQ Disable</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">1=</span>禁止</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">0=</span>允許</div>
</td></tr>
<tr class="alt" valign="TOP"><td height="25" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">8</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">A</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Imprecise About Bit</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">A-bit</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">o Indicates if imprecise data abort exceptions are masked</span></div>
</td></tr>
<tr valign="TOP"><td height="26" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">9</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">E</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Data Endianess Bit</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">E-bit</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">o Indicates the current load/store endian setting of the core</span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">o Can be set/cleared with the SETEND instruction</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="24" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">10</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">c</span></td><td rowspan="4" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">IT state bits</span></td></tr>
<tr valign="TOP"><td height="22" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">11</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">b</span></td></tr>
<tr class="alt" valign="TOP"><td height="31" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">12</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">a</span></td></tr>
<tr valign="TOP"><td height="18" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">15-13</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">IT_cond</span></td></tr>
<tr class="alt" valign="TOP"><td height="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">19-16</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">GR[3:0]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Greater than or equal to</span></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">23-20</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">DNM (RAZ)</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"></td></tr>
<tr class="alt" valign="TOP"><td height="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">24</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">J</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Java State Bit</span></td></tr>
<tr valign="TOP"><td height="18" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">25</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">e</span></td><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">IT state bits</span></td></tr>
<tr class="alt" valign="TOP"><td height="11" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">26</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">d</span></td></tr>
<tr valign="TOP"><td height="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">27</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">Q</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Sticky Overflow</span></td></tr>
<tr class="alt" valign="TOP"><td height="25" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">28</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">V</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Overflow</span></td></tr>
<tr valign="TOP"><td height="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">29</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">C</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Carry/Borrow/Extend</span></td></tr>
<tr class="alt" valign="TOP"><td height="25" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">30</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">Z</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Zero</span></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">31</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">N</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Negative/Less than</span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>E, APSR (Application Program Status Register)</strong></span></span><span style="font-size: small;"><strong>算術邏輯單元狀態標誌</strong></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
不同於<span style="font-family: "Times New Roman", serif;">CPSR</span>與<span style="font-family: "Times New Roman", serif;">SPSR,APSR</span>主要是作為<span style="font-family: "Times New Roman", serif;">ALU(Arithmetic Logic Unit)</span>狀態標誌的暫存器<span style="font-family: "Times New Roman", serif;">,</span>用以決定這些<span style="font-family: "Times New Roman", serif;">Condition</span>指令是否被執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">CPSR</span>也會包含<span style="font-family: "Times New Roman", serif;">APSR</span>的<span style="font-family: "Times New Roman", serif;">Flags,</span>其他像是處理器的狀態<span style="font-family: "Times New Roman", serif;">,</span>中斷的致能與否<span style="font-family: "Times New Roman", serif;">,</span>目前的指令集狀態<span style="font-family: "Times New Roman", serif;">,</span>執行狀態<span style="font-family: "Times New Roman", serif;">IT block,</span>這些都是<span style="font-family: "Times New Roman", serif;">APSR</span>所不包含的<span style="font-family: "Times New Roman", serif;">.</span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 913px;"><colgroup><col width="100"></col><col width="161"></col><col width="638"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td height="23" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">位元</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161">功能</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638">說明</td></tr>
<tr valign="TOP"><td height="27" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">15-0</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">Reserved</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Reserved</span></td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">19-16</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">GE[3:0]</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Greater than or equal to (SIMD status bits – greater than or equal to for each 8/16-bit slice)</span></td></tr>
<tr valign="TOP"><td height="34" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">23-20</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">Reserved</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Reserved</span></td></tr>
<tr class="alt" valign="TOP"><td height="25" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">26-24</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">RAZ/SBZP</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">27</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">Q</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Sticky Overflow</span></td></tr>
<tr class="alt" valign="TOP"><td height="26" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">28</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">V</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Overflow</span></td></tr>
<tr valign="TOP"><td height="22" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">29</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">C</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Carry/Borrow/Extend</span></td></tr>
<tr class="alt" valign="TOP"><td height="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">30</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">Z</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Zero</span></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">31</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">N</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;">Negative/Less than</span></td></tr>
<tr class="alt" valign="TOP"><td height="1" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">接下來介紹其他</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">處理器主要的特徵</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span></div>
<h4 id="14512_1-coprocessors_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: small;">1,</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"> </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;">Coprocessors</span></span></h4>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">本身除了支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARMv32,Thumb,Thumb2</span></span><span style="font-size: x-small;">指令集外</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">還可以透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">支援延伸的指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">每當</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">處理器執行到無法識別的指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor </span></span><span style="font-size: x-small;">試圖進行指令集的識別動作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">無法識別有效的指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">或是該系統沒有對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">配置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會透過觸發</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Undefined Instruction Vector</span></span><span style="font-size: x-small;">透過對應的軟體進行錯誤處理流程 (</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Undefined Instruction</span></span><span style="font-size: x-small;">通常也會用在安插</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Break Point</span></span><span style="font-size: x-small;">的除錯機制上)</span><span style="font-size: x-small;">ㄜ</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">可以支持</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0-15</span></span><span style="font-size: x-small;">共</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor,</span></span><span style="font-size: x-small;">例如</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">: CP15(System Control Coprocessor 15)</span></span><span style="font-size: x-small;">一般是用在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Cache</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">MMU</span></span><span style="font-size: x-small;">相關的設定工作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,CP14(Debug Control Coprocessor 14)</span></span><span style="font-size: x-small;">支援相關</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Debug Registers,</span></span><span style="font-size: x-small;">其它像是新增的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NEON MPE (Media Processing Engine) SIMD</span></span><span style="font-size: x-small;">指令與浮點運算</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">VFP</span></span><span style="font-size: x-small;">是透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CP10</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CP11</span></span><span style="font-size: x-small;">支援 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">可參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Cortex A8 Technical Reference Manual</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0450b/ch02s01s02.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0450b/ch02s01s02.html</a></span></span><span style="font-size: x-small;">).</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">目前所提供的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">指令中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">有針對</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">VFP</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NEON</span></span><span style="font-size: x-small;">的指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">定義對應的指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">舉在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Cortext A</span></span><span style="font-size: x-small;">中有支援的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NEON</span></span><span style="font-size: x-small;">指令集為例</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在編譯器端只要加入 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">vectorize </span></span><span style="font-size: x-small;">參數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就可以主動由編譯器根據程式碼內容優化</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NEON</span></span><span style="font-size: x-small;">的指令集進行產生對應的指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如下所示</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">armcc –vectorize -c vector.c –cpu Cortex-A8 -Otime</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">之後反組譯 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">vector.o,</span></span><span style="font-size: x-small;">如下所示</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000a0: f2944a40 @J.. VMULL.S16 q2,d4,d0[0] => NEON</span></span><span style="font-size: x-small;">指令集</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000a4: f428774f Ow(. VLD1.16 {d7},[r8]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000a8: e2868006 …. ADD r8,r6,#6</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000ac: e2866008 .`.. ADD r6,r6,#8</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000b0: f428674f Og(. VLD1.16 {d6},[r8]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000b4: f2974248 HB.. VMLAL.S16 q2,d7,d0[1]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000b8: f426174f O.&. VLD1.16 {d1},[r6]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000bc: f2964260 `B.. VMLAL.S16 q2,d6,d0[2]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000c0: f2914268 hB.. VMLAL.S16 q2,d1,d0[3]</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0x000000c4: f2222844 D(“. VADD.I32 q1,q1,q2</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">而這些</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NEON</span></span><span style="font-size: x-small;">指令集就會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CP10</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CP11</span></span><span style="font-size: x-small;">支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">不需要使用者自己透過跟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">的資料交換指令來完成</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NEON</span></span><span style="font-size: x-small;">指令集的優化動作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">如果今天使用的是基於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">GPU,</span></span><span style="font-size: x-small;">由於編譯器跟處理器都沒有對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">GPU</span></span><span style="font-size: x-small;">指令集支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">我們會需要透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">指令去包裝這些</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">GPU</span></span><span style="font-size: x-small;">指令集的動作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">由開發端根據對</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">GPU</span></span><span style="font-size: x-small;">指令了解的深度</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">優化圖形的函式庫</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">達到透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">GPU</span></span><span style="font-size: x-small;">加速的目的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">架構也可以用來支援不同的周邊</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">除了</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">可以驅動周邊外</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Coprocessor</span></span><span style="font-size: x-small;">也能連接周邊</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">進行相關必要的工作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">例如</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">: Graphics Coprocessor,</span></span><span style="font-size: x-small;">可主動的計算與處理資料</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">並更新</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Display</span></span><span style="font-size: x-small;">記憶體</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Coprocessor</span></span><span style="font-size: x-small;">對</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">核心而言</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就是另外一個協同處理器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">連接到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Data</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Control Bus</span></span><span style="font-size: x-small;">上</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">當</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">處理器遇到無法解析的指令時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會初始化與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Handshaking</span></span><span style="font-size: x-small;">流程</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">進行後續的執行工作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">之間可以透過以下三個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Signal</span></span><span style="font-size: x-small;">進行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Handshaking.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><strong>A,</strong></span><span style="font-family: Arial, sans-serif;"><strong> CPI (Co-processor instruction) Signal</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">在系統上的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">都會監聽這個訊息的發生</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">每當</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">遇到一個無法識別的指令集時就會觸發這個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Signal.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><strong>B, </strong></span><span style="font-family: Arial, sans-serif;"><strong>CPA (Co-processor absent) Signal</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">當</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">接收到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CPI Signal</span></span><span style="font-size: x-small;">時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會把該指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Fetch</span></span><span style="font-size: x-small;">進來</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">並透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CPA Signal</span></span><span style="font-size: x-small;">回應</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">是否支援這個指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">舉例來說如果</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">支援該指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CPA Signal</span></span><span style="font-size: x-small;">設定為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Low (</span></span><span style="font-size: x-small;">反之</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">不支持該指令集就把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CPA</span></span><span style="font-size: x-small;">設定為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">High),</span></span><span style="font-size: x-small;">並透過</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">B.1, </span><span style="font-size: x-small;">A</span></span><span style="font-size: x-small;">集就是高電位電ㄨㄟㄢ</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">sor absent..tor</span><span style="font-size: x-small;">1bit</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Signal Bit</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1</span></span><span style="font-size: x-small;">表示該指令集可被</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">處理</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0</span></span><span style="font-size: x-small;">表示不支援該指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">B.2, 4bits (0-15)</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor ID</span></span><span style="font-size: x-small;">表示目前可處理該指令集是哪一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor (</span></span><span style="font-size: x-small;">最多</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">).</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-size: x-small;">如果沒有任何一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">能處理該指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,CPA Signal</span></span><span style="font-size: x-small;">就會保持在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">High,</span></span><span style="font-size: x-small;">而</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">就會進一步觸發</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Undefined Instruction Vector</span></span><span style="font-size: x-small;">後續流程</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;"><strong>C, </strong></span><span style="font-family: Arial, sans-serif;"><strong>CPB (Co-processor busy) Signal</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">一旦</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">回應</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">可以執行該指令集後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,ARM</span></span><span style="font-size: x-small;">就會透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CPB Signal</span></span><span style="font-size: x-small;">確認目前</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">的執行狀態</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果這個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Signal</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">High</span></span><span style="font-size: x-small;">表示</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">目前尚未結束前一個處理中的指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.CPB Signal</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Low,</span></span><span style="font-size: x-small;">表示</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">可以準備處理下一個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">當</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的程式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">處於執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">指令的狀態時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,ARM</span></span><span style="font-size: x-small;">會等待該指令集執行結束</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">才讓程式繼續運作下去</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在我們一般多工的系統當中</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">例如</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Linux Kernel 2.6</span></span><span style="font-size: x-small;">每一秒會觸發</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1000</span></span><span style="font-size: x-small;">次的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">System Timer</span></span><span style="font-size: x-small;">中斷觸發核心排程的機制</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">在等待</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">執行完畢的過程中發生</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的中斷</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">這次</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">指令執行的動作就會中斷</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">等到該中斷執行結束</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">重新返回該應用程式該處指令集位址</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">重新該次</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">指令的執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Linux</span></span><span style="font-size: x-small;">環境為例</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果這時候行程已經透過核心排程到其它應用程式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就要等到下一次該應用程式被排程到後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">才有機會重新把該</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">指令重新執行完畢</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">一般而言</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,Coprocessor</span></span><span style="font-size: x-small;">指令可以分為以下三種類型</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1, </span></span><span style="font-size: x-small;">純粹為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">內部的操作流程</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,ARM</span></span><span style="font-size: x-small;">端無須參與</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">這類的指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,ARM</span></span><span style="font-size: x-small;">不需要等待</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">傳回資料</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">也不用等待</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">執行該指令集結束</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">純粹為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Coprocessor</span></span><span style="font-size: x-small;">內部的資料處理</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,ARM</span></span><span style="font-size: x-small;">能立刻繼續往下執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CDP(Coprocessor Data Processing)</span></span><span style="font-size: x-small;">指令為例</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CDP{cond} <cp#>,<op>,<dest>,<lhs>,<rhs>,{info}</span></span></div>
<dl style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;"><dd><table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 883px;"><colgroup><col width="145"></col><col width="728"></col></colgroup><tbody>
<tr valign="TOP"><td height="31" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;">{cond}</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728">執行指令條件判斷<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">,</span></span>當條件滿足才會執行此指令<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">(the optional condition code)</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="26" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><cp#></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">Coprocessor</span></span>編號<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">(0-15,4bits,the co-processor number)</span></span></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><op></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728">所要執行<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">Coprocessor</span></span>的指令編號<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">(0-15,4bits,the desired operation code)</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="24" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><dest></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728">在<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">Coprocessor</span></span>端儲存資料的目標暫存器<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">(0-15,4bits,the co-processor destination register)</span></span></td></tr>
<tr valign="TOP"><td height="24" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><strong><lhs> </strong></span><span style="font-family: Arial, sans-serif;">and </span><span style="font-family: "Courier New", monospace;"><strong><rhs></strong></span><span style="font-family: Arial, sans-serif;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728">在<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">Coprocessor</span></span>端讀取資料的來源暫存器<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">(0-15,4bits,the co-processor source registers)</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="1" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><strong>{info}</strong></span><span style="font-family: Arial, sans-serif;"></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: Arial, sans-serif;">Info (0-7,3bits,the optional additional information field)</span></td></tr>
</tbody></table>
</dd></dl>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
另一個例子為<span style="font-family: "Times New Roman", serif;">,FPU Coprocessor</span>指令的例子</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong></strong><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>ADF {cond}<P>{R} <dest>,<lhs>,<rhs></strong></span></span></span></div>
<dl style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;"><dd><table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 883px;"><colgroup><col width="145"></col><col width="728"></col></colgroup><tbody>
<tr valign="TOP"><td height="31" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;">{cond}</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728">執行指令條件判斷<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">,</span></span>當條件滿足才會執行此指令<span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, sans-serif;">(the optional condition code)</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="26" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><P></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: Arial, sans-serif;"><span style="font-size: small;">the precision of the operation</span></span></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;">{R}</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: Arial, sans-serif;"><span style="font-size: small;">the optional rounding mode and the other fields are as above.</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="24" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><dest></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728">目標暫存器</td></tr>
<tr valign="TOP"><td height="24" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><strong><lhs></strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728">來源暫存器</td></tr>
<tr class="alt" valign="TOP"><td height="1" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Courier New", monospace;"><strong><rhs></strong></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728">來源暫存器</td></tr>
</tbody></table>
</dd></dl>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
或是<span style="font-family: "Times New Roman", serif;">Graphics Coprocessor</span>指令的例子</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">CDP 2,<palette>,<entry>,<value>,<component></span></div>
<dl style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;"><dd><table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 883px;"><colgroup><col width="145"></col><col width="728"></col></colgroup><tbody>
<tr valign="TOP"><td height="31" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Times New Roman", serif;"><cp#></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: Arial, sans-serif;">2 is the co-processor number</span></td></tr>
<tr class="alt" valign="TOP"><td height="26" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong><palette></strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: Arial, sans-serif;"><span style="font-size: small;">the op-code for setting the palette</span></span></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong><entry></strong></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: Arial, sans-serif;">the logical colour number (0-15) (the <dest> field)</span></td></tr>
<tr class="alt" valign="TOP"><td height="24" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong><value></strong></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: Arial, sans-serif;">the intensity for that component (0-65535) (the <lhs> and <rhs>) field.</span></td></tr>
<tr valign="TOP"><td height="23" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="145"><span style="font-family: Arial, sans-serif;"><component></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="728"><span style="font-family: Arial, sans-serif;">the red, green or blue component (0-2) (the info field)</span></td></tr>
</tbody></table>
</dd></dl>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">2, </span>需要透過<span style="font-family: "Times New Roman", serif;">ARM</span>的暫存器跟<span style="font-family: "Times New Roman", serif;">Coprocessor</span>暫存器進行資料的交換</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
第二類的指令集<span style="font-family: "Times New Roman", serif;">,</span>為<span style="font-family: "Times New Roman", serif;">ARM</span>跟<span style="font-family: "Times New Roman", serif;">Coprocessor</span>透過暫存器進行資料的處理更新<span style="font-family: "Times New Roman", serif;">,</span>由於會牽涉到<span style="font-family: "Times New Roman", serif;">ARM</span>端暫存器的內容更動<span style="font-family: "Times New Roman", serif;">,</span>因此<span style="font-family: "Times New Roman", serif;">ARM</span>必須要等待<span style="font-family: "Times New Roman", serif;">Coprocessor</span>處理完畢才可以繼續執行下去<span style="font-family: "Times New Roman", serif;">,</span>以確保跟<span style="font-family: "Times New Roman", serif;">Coprocessor</span>交換資料的動作<span style="font-family: "Times New Roman", serif;">,</span>跟原本程式設計預期的行為流程的正確性<span style="font-family: "Times New Roman", serif;">,</span>以下舉<span style="font-family: "Times New Roman", serif;">MRC (Move to arm core Register from Coprocessor) </span>與 <span style="font-family: "Times New Roman", serif;">MCR(Move to Coprocessor from arm core Register)</span>兩個指令為例</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong></strong><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>MRC{cond} <cp#>,<op>,<ARM dest>,<lhs>,<rhs>,{info}<br />MCR{cond} <cp#>,<op>,<ARM srce>,<lhs>,<rhs>,{info}</strong></span></span></span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 898px;"><colgroup><col width="220"></col><col width="668"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td height="23" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">{cond}</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668">指令集條件判斷<span style="font-family: "Times New Roman", serif;">(the optional condition code)</span></td></tr>
<tr valign="TOP"><td height="22" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><cp#></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668"><span style="font-family: "Times New Roman", serif;">Coprocessor</span>編號<span style="font-family: "Times New Roman", serif;">(4bits,0-15,<span style="font-family: Arial, sans-serif;"> the co-processor number</span>)</span></td></tr>
<tr class="alt" valign="TOP"><td height="19" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><op></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668">所要執行<span style="font-family: "Times New Roman", serif;">Coprocessor</span>的動作編號<span style="font-family: "Times New Roman", serif;">(3bits,0-7,<span style="font-family: Arial, sans-serif;"> the operation code required)</span></span></td></tr>
<tr valign="TOP"><td height="17" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><ARM dest></span><span style="font-family: Arial, sans-serif;">/</span><span style="font-family: "Courier New", monospace;"><ARM srce></span><span style="font-family: Arial, sans-serif;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668">在<span style="font-family: "Times New Roman", serif;">ARM</span>端要跟<span style="font-family: "Times New Roman", serif;">Coprocessor</span>交換資料的暫存器<span style="font-family: "Times New Roman", serif;">(4bits,0-15,<span style="font-family: Arial, sans-serif;"> the ARM source/destination register</span>)</span></td></tr>
<tr class="alt" valign="TOP"><td height="31" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><lhs></span><span style="font-family: Arial, sans-serif;"> and </span><span style="font-family: "Courier New", monospace;"><rhs></span></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668">在<span style="font-family: "Times New Roman", serif;">Coprocessor</span>端要跟<span style="font-family: "Times New Roman", serif;">ARM</span>交換資料的暫存器<span style="font-family: "Times New Roman", serif;">(4bits,0-15,<span style="font-family: Arial, sans-serif;"> co-processor register numbers)</span></span></td></tr>
<tr valign="TOP"><td height="25" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">{info}</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668">附加額外資訊<span style="font-family: "Times New Roman", serif;">(3bits,0-7,<span style="font-family: Arial, sans-serif;"> optional extra information)</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">3, Coprocessor </span>透過外部記憶體存取相關資料進行處理</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
類似於<span style="font-family: "Times New Roman", serif;">ARM</span>的<span style="font-family: "Times New Roman", serif;">LDR/STR</span>指令可以把記憶體資料儲存到<span style="font-family: "Times New Roman", serif;">ARM</span>的暫存器<span style="font-family: "Times New Roman", serif;">,</span>或是把<span style="font-family: "Times New Roman", serif;">ARM</span>暫存器的資料寫到記憶體終<span style="font-family: "Times New Roman", serif;">,</span>針對<span style="font-family: "Times New Roman", serif;">Coprocessor</span>的操作也有類似的指令<span style="font-family: "Times New Roman", serif;">LDC/STC,</span>這個指令可以針對一個<span style="font-family: "Times New Roman", serif;">Array</span>作範圍不超過<span style="font-family: "Times New Roman", serif;">-255 to +255 words (-1020 to +1020 bytes)</span>的<span style="font-family: "Times New Roman", serif;">index</span>動作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">LDC{cond}{L} <cp#>,<dest>,<address><br />STC{cond}{L} <cp#>,<srce>,<address></span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 898px;"><colgroup><col width="220"></col><col width="668"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td height="23" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;">{cond}</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668">指令集條件判斷<span style="font-family: "Times New Roman", serif;">(the optional condition code)</span></td></tr>
<tr valign="TOP"><td height="22" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><span style="font-size: xx-small;"><strong>{L}</strong></span></span><span style="font-family: Arial, sans-serif;"><span style="font-size: small;"></span></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668"><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: Arial, sans-serif;"><span style="font-size: small;">optional bit meaning ‘long transfer’)</span></span></td></tr>
<tr class="alt" valign="TOP"><td height="19" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><cp#></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668"><span style="font-family: "Times New Roman", serif;">Coprocessor</span>編號<span style="font-family: "Times New Roman", serif;">(4bits,0-15,<span style="font-family: Arial, sans-serif;"> the co-processor number</span>)</span></td></tr>
<tr valign="TOP"><td height="17" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><span style="font-family: "Courier New", monospace;"><dest></span><span style="font-family: Arial, sans-serif;">/</span><span style="font-family: "Courier New", monospace;"><srce></span><span style="font-family: Arial, sans-serif;"></span></span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668">在<span style="font-family: "Times New Roman", serif;">Coprocessor</span>端要跟記憶體交換資料的暫存器<span style="font-family: "Times New Roman", serif;">(4bits,0-15,<span style="font-family: Arial, sans-serif;"> the ARM source/destination register</span>)</span></td></tr>
<tr class="alt" valign="TOP"><td height="30" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="220"><span style="font-family: "Times New Roman", serif;"><address></span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="668"><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: Arial, sans-serif;"><span style="font-size: small;">specifies the address at which to start transferring data)</span></span></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Coprocessor</span>跟<span style="font-family: "Times New Roman", serif;">ARM</span>指令集一樣<span style="font-family: "Times New Roman", serif;">,</span>都可以支援讓部分指令集只能在<span style="font-family: "Times New Roman", serif;">SVC Mode (Supervisor Mode)</span>下被執行<span style="font-family: "Times New Roman", serif;">,ARM</span>可以透過<span style="font-family: "Times New Roman", serif;">SPVMD Signal</span>告訴外部的裝置或是<span style="font-family: "Times New Roman", serif;">Coprocessor</span>目前執行中的<span style="font-family: "Times New Roman", serif;">ARM</span>程式是否處於<span style="font-family: "Times New Roman", serif;">SVC Mode,</span>讓周邊或是<span style="font-family: "Times New Roman", serif;">Coprocessor</span>可以判別是否繼續改動作或指令的執行<span style="font-family: "Times New Roman", serif;">. Coprocessor</span>可以透過觸發<span style="font-family: "Times New Roman", serif;">Abort</span>中止該次指令的執行動作<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以浮點數來說<span style="font-family: "Times New Roman", serif;">,</span>並不是所有<span style="font-family: "Times New Roman", serif;">ARM</span>的平台都有支援<span style="font-family: "Times New Roman", serif;">VFP Coprocessor,</span>因此在透過<span style="font-family: "Times New Roman", serif;">RVCT ARM</span>編譯器時<span style="font-family: "Times New Roman", serif;">,</span>可以透過 “<span style="font-family: "Times New Roman", serif;">– -fpu=vfp” </span>選擇硬體支援的<span style="font-family: "Times New Roman", serif;">VFP Coprocessor</span>指令<span style="font-family: "Times New Roman", serif;">,</span>讓編譯器可以產生使用<span style="font-family: "Times New Roman", serif;">VFP</span>指令集的機械碼<span style="font-family: "Times New Roman", serif;">,</span>若是該平台沒有支援<span style="font-family: "Times New Roman", serif;">VFP,</span>就可以選擇編譯參數 “<span style="font-family: "Times New Roman", serif;">– -fpu=softvfp”,</span>讓編譯器以軟體的方式處理浮點運算<span style="font-family: "Times New Roman", serif;">,</span>不要產生基於<span style="font-family: "Times New Roman", serif;">VFP</span>的<span style="font-family: "Times New Roman", serif;">Coprocessor</span>指令集<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
除此之外<span style="font-family: "Times New Roman", serif;">,</span>也可以透過支援<span style="font-family: "Times New Roman", serif;">VFP</span>的函式庫<span style="font-family: "Times New Roman", serif;">,</span>還是讓編譯器產生基於<span style="font-family: "Times New Roman", serif;">VFP Coprocessor</span>的指令集機械碼<span style="font-family: "Times New Roman", serif;">,</span>當<span style="font-family: "Times New Roman", serif;">ARM</span>處理到這些指令集時<span style="font-family: "Times New Roman", serif;">,</span>就會進行上述對<span style="font-family: "Times New Roman", serif;">Coprocessor</span>的流程<span style="font-family: "Times New Roman", serif;">,</span>若平台上面沒有對應的<span style="font-family: "Times New Roman", serif;">VFP Coprocessor</span>支援<span style="font-family: "Times New Roman", serif;">,</span>就會觸發<span style="font-family: "Times New Roman", serif;">Undefined Instruction Trap,</span>再透過<span style="font-family: "Times New Roman", serif;">ARM</span>端處理<span style="font-family: "Times New Roman", serif;">Undefined Instruction Trap</span>的軟體流程<span style="font-family: "Times New Roman", serif;">,</span>呼叫對應於<span style="font-family: "Times New Roman", serif;">VFP</span>指令集的軟體實作函式庫<span style="font-family: "Times New Roman", serif;">. (</span>參考文件<span style="font-family: "Times New Roman", serif;">RealView Compilation Tools Libraries and Floating Point Support Guide).</span></div>
<h4 id="14512_2-jazelle_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2, Jazelle</span></span></h4>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的網站</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">http://www.arm.com/products/processors/technologies/jazelle.php, Jazelle</span></span><span style="font-size: x-small;">是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">2002</span></span><span style="font-size: x-small;">年開始的計畫</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">主要的目的是讓</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">可以無須經由一層軟體的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">JVM,</span></span><span style="font-size: x-small;">能夠如同一般</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARMv32</span></span><span style="font-size: x-small;">指令集一樣</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">直接透過處理器執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">加速</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">應用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">的執行效率</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span><span style="font-size: x-small;">第一個具備</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazalle</span></span><span style="font-size: x-small;">指令集的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">核心是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARMv5TEJ,</span></span><span style="font-size: x-small;">所產生的第一個處理器產品是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM926EJ-S.</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">核心</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">會在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Pipeline Fecth</span></span><span style="font-size: x-small;">到指令後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">把所讀取到的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">轉為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1</span></span><span style="font-size: x-small;">個或多個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">並由</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java Vm</span></span><span style="font-size: x-small;">把要執行的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">程式預備好後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">再透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">BXJ </span></span><span style="font-size: x-small;">進行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Branch</span></span><span style="font-size: x-small;">與轉態為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">指令集的動作</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">跳到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">程式中執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">由於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle</span></span><span style="font-size: x-small;">主要實作常用的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java </span></span><span style="font-size: x-small;">指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果遇到不支援的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">指令</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就會通知</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Software Java Vm</span></span><span style="font-size: x-small;">協助執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">回到</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">或是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Thumb Mode),</span></span><span style="font-size: x-small;">之後再由</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java Vm</span></span><span style="font-size: x-small;">根據需求切回</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle</span></span><span style="font-size: x-small;">模式下</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">ㄟ</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">…</span></span><span style="font-size: x-small;">因為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">筆者沒實際操刀過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle,</span></span><span style="font-size: x-small;">但由於</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle</span></span><span style="font-size: x-small;">模式下是可以觸發</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Undefined Instruction Exception</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">個人覺得當</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle</span></span><span style="font-size: x-small;">遇到不支援的指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">通知</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Software Java VM</span></span><span style="font-size: x-small;">的方式應該是透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Undefined Instruction Exception</span></span><span style="font-size: x-small;">由</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">SPSR</span></span><span style="font-size: x-small;">判斷前一個狀態是不是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle</span></span><span style="font-size: x-small;">指令模式</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就再透過</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Softwaft Java Vm</span></span><span style="font-size: x-small;">去執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">可以參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">LR </span></span><span style="font-size: x-small;">知道該</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ByteCode</span></span><span style="font-size: x-small;">指令的位置</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.). </span></span><span style="font-size: x-small;">另外一種可能就是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">採用類似</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ThumbEE Handler</span></span><span style="font-size: x-small;">的作法</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果遇到無法支援的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java ByteCode</span></span><span style="font-size: x-small;">指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">就透過該</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Handler</span></span><span style="font-size: x-small;">交給</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Software Java Vm</span></span><span style="font-size: x-small;">執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.(</span></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0388f/Bhhggafj.html" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-size: x-small;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0388f/Bhhggafj.html</span></a></span></span><span style="font-size: x-small;"> and </span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344c/Chdiciaj.html" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-size: x-small;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344c/Chdiciaj.html</span></a></span></span><span style="font-size: x-small;"> ),</span><span style="font-size: x-small;">以上僅供參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">…:)</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">可以參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Sun</span></span><span style="font-size: x-small;">在 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">CLDC HI(HotSpot Implementation)</span></span><span style="font-size: x-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Release </span></span><span style="font-size: x-small;">文件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://download.oracle.com/javame/config/cldc/cldc-opt-impl/cldc-hi-2.0-web/doc/release/CLDC_HI-release-notes.html" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-size: x-small;">http://download.oracle.com/javame/config/cldc/cldc-opt-impl/cldc-hi-2.0-web/doc/release/CLDC_HI-release-notes.html</span></a></span></span><span style="font-size: x-small;"> ),CDLD Hi</span></span><span style="font-size: x-small;">有支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java Just-In Time</span></span><span style="font-size: x-small;">的機制</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">可以即時把</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java ByteCode</span></span><span style="font-size: x-small;">編譯為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM Code,</span></span><span style="font-size: x-small;">加速</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Java</span></span><span style="font-size: x-small;">應用的執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">如果要開啟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Jazelle</span></span><span style="font-size: x-small;">加速的話</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">文件中有說明需要取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">的授權後</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">才能使用</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">『</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: x-small;">For the avoidance of doubt, distribution of products containing software code to exercise the BXJ instruction and enable the use of the ARM Jazelle architecture extension without a JTEK licensing agreement from ARM is expressly forbidden.</span></span><span style="font-size: x-small;"> </span></span><span style="font-size: x-small;">』</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">. </span></span><span style="font-size: x-small;">由於需要取得</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM JTEK</span></span><span style="font-size: x-small;">授權</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">才能啟用這功能</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在實際的應用上</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">應該都會比較偏向用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">JIT</span></span><span style="font-size: x-small;">來做加速</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">通常會根據</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARMv5</span></span><span style="font-size: x-small;">指令集做優化</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">).</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前<span style="font-family: "Times New Roman", serif;">Jazelle</span>的應用主要可以分為</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">A, Jazelle DBX(Direct Binary Execution): </span>主要提供執行讓<span style="font-family: "Times New Roman", serif;">Java ByteCode</span>可以在<span style="font-family: "Times New Roman", serif;">ARM</span>處理器上執行的能力<span style="font-family: "Times New Roman", serif;">,</span>開發端可以判斷處理器當下的<span style="font-family: "Times New Roman", serif;">CPSR J(bit 24)</span>是否為<span style="font-family: "Times New Roman", serif;">1 </span>與 <span style="font-family: "Times New Roman", serif;">T (bit 5)</span>是否為<span style="font-family: "Times New Roman", serif;">0,</span>確認處理器是否處於<span style="font-family: "Times New Roman", serif;">ARM Jazelle</span>指令集的模式<span style="font-family: "Times New Roman", serif;">. </span>可用來減輕透過<span style="font-family: "Times New Roman", serif;">ARM</span>指令集運作 <span style="font-family: "Times New Roman", serif;">Java Vm</span>執行<span style="font-family: "Times New Roman", serif;">ByteCode</span>的運算成本<span style="font-family: "Times New Roman", serif;">. </span>直接藉由處理器的指令支援<span style="font-family: "Times New Roman", serif;">,</span>加速運作的效率<span style="font-family: "Times New Roman", serif;">. </span>要讓<span style="font-family: "Times New Roman", serif;">Jazelle</span>能夠有效運作<span style="font-family: "Times New Roman", serif;">,</span>這也需要<span style="font-family: "Times New Roman", serif;">Java Vm</span>支援<span style="font-family: "Times New Roman", serif;">(Jazelle-aware JVM),</span>以便讓<span style="font-family: "Times New Roman", serif;">Java</span>應用程式所需相關的<span style="font-family: "Times New Roman", serif;">JSR(Java Specification Requests)</span>或是<span style="font-family: "Times New Roman", serif;">JAR</span>的讀取<span style="font-family: "Times New Roman", serif;">,</span>能夠搭配<span style="font-family: "Times New Roman", serif;">Jazelle</span>流程被妥善應用<span style="font-family: "Times New Roman", serif;">,</span>根據<span style="font-family: "Times New Roman", serif;">ARM</span>的宣稱<span style="font-family: "Times New Roman", serif;">,</span>有約<span style="font-family: "Times New Roman", serif;">95%</span>的<span style="font-family: "Times New Roman", serif;">ByteCode</span>應用程式<span style="font-family: "Times New Roman", serif;">,</span>可以直接透過<span style="font-family: "Times New Roman", serif;">Jazelle</span>執行<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">B, Jazelle RCT(Runtime Compile Target): </span>這個技術<span style="font-family: "Times New Roman", serif;">,</span>主要用來將<span style="font-family: "Times New Roman", serif;">Java ByteCode</span>轉為<span style="font-family: "Times New Roman", serif;">ARM</span>的機械碼<span style="font-family: "Times New Roman", serif;">(</span>根據參考的資料<span style="font-family: "Times New Roman", serif;">,ByteCode</span>轉為<span style="font-family: "Times New Roman", serif;">ARM</span>機械碼後<span style="font-family: "Times New Roman", serif;">,</span>最終程式的大小會膨脹<span style="font-family: "Times New Roman", serif;">4-8</span>倍<span style="font-family: "Times New Roman", serif;">). JIT</span>或是<span style="font-family: "Times New Roman", serif;">DAC(Dynamic Adaptive Compilation)</span>可以根據<span style="font-family: "Times New Roman", serif;">Java ByteCode</span>執行的情況<span style="font-family: "Times New Roman", serif;">,</span>動態的分析並編譯<span style="font-family: "Times New Roman", serif;">ByteCode,Jazelle RCT</span>希望解決的問題是<span style="font-family: "Times New Roman", serif;">,</span>讓透過軟體將<span style="font-family: "Times New Roman", serif;">ByteCode</span>轉機械碼的過程中<span style="font-family: "Times New Roman", serif;">,</span>所造成的應用程式啟動時間增加<span style="font-family: "Times New Roman", serif;">,</span>功耗與執行效能受到影響的問題<span style="font-family: "Times New Roman", serif;">,</span>可以透過<span style="font-family: "Times New Roman", serif;">Jazelle RCT</span>加以避免<span style="font-family: "Times New Roman", serif;">. </span>在實際的應用上<span style="font-family: "Times New Roman", serif;">,</span>也可以透過<span style="font-family: "Times New Roman", serif;">AOT(ahead-of-time)</span>提前在安裝或下載應用時進行編譯為<span style="font-family: "Times New Roman", serif;">ARM</span>機械碼<span style="font-family: "Times New Roman", serif;">,</span>當然<span style="font-family: "Times New Roman", serif;">,</span>因為編譯後的<span style="font-family: "Times New Roman", serif;">Java</span>應用會讓儲存空間膨脹<span style="font-family: "Times New Roman", serif;">4-8</span>倍<span style="font-family: "Times New Roman", serif;">,</span>在評估上也需要加以考量<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前<span style="font-family: "Times New Roman", serif;">Android 2.2</span>之後的<span style="font-family: "Times New Roman", serif;">Dalvik</span>也有支援<span style="font-family: "Times New Roman", serif;">JIT,</span>筆者認為以後軟體的<span style="font-family: "Times New Roman", serif;">JIT</span>應該會是主流<span style="font-family: "Times New Roman", serif;">,</span>透過<span style="font-family: "Times New Roman", serif;">Jazelle DBX</span>或是<span style="font-family: "Times New Roman", serif;">RCT</span>的機制<span style="font-family: "Times New Roman", serif;">,</span>由於授權的限制<span style="font-family: "Times New Roman", serif;">,</span>應該不容易成為應用的主流<span style="font-family: "Times New Roman", serif;">.(</span>當然<span style="font-family: "Times New Roman", serif;">Jazelle</span>也需要處理器的支援<span style="font-family: "Times New Roman", serif;">.)</span></div>
<h4 id="14512_3-armv32_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">3, ARMv32</span></span></h4>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARMv32</span></span></span><span style="font-size: xx-small;">是</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARM</span></span></span><span style="font-size: xx-small;">原生的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">32bits</span></span></span><span style="font-size: xx-small;">指令集環境</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">也是相比於</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb(16bits)</span></span></span><span style="font-size: xx-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb2(16/32bits)</span></span></span><span style="font-size: xx-small;">執行環境來說</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">可以得到最佳化的執行效能</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,ARM</span></span></span><span style="font-size: xx-small;">指令在記憶體中會與</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">4bytes</span></span></span><span style="font-size: xx-small;">位址對齊</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">.</span></span></span><span style="font-size: xx-small;">通常在要求性能</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">例外或系統初始化的部分</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">會採用</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARM 32bits</span></span></span><span style="font-size: xx-small;">指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">.</span></span></span><span style="font-size: xx-small;">指令集編碼特徵是每個指令最高</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">4bits</span></span></span><span style="font-size: xx-small;">會代表該指令執行條件</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></div>
<h4 id="14512_4-thumb_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4, Thumb</span></span></h4>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb16bits</span></span></span><span style="font-size: xx-small;">指令集主要是以常用的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARM 32bits</span></span></span><span style="font-size: xx-small;">指令集為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Subset</span></span></span><span style="font-size: xx-small;">去設計的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">在處理器中會把所載入的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">16bits Thumb</span></span></span><span style="font-size: xx-small;">指令轉成對應的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">32 bits ARM </span></span></span><span style="font-size: xx-small;">指令去執行</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">開發端可以根據</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">CPSR</span></span></span><span style="font-size: xx-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">T </span></span></span><span style="font-size: xx-small;">是否為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">1</span></span></span><span style="font-size: xx-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">J</span></span></span><span style="font-size: xx-small;">是否為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">0,</span></span></span><span style="font-size: xx-small;">判定是否為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb Mode. </span></span></span><span style="font-size: xx-small;">在開發上需要注意的是</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">同樣的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">C</span></span></span><span style="font-size: xx-small;">程式碼採用</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb 16bits</span></span></span><span style="font-size: xx-small;">指令集</span><span style="font-size: xx-small;">編譯後</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">執行</span><span style="font-size: xx-small;">效率</span><span style="font-size: xx-small;">會有所減損</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">指令</span><span style="font-size: xx-small;">也</span><span style="font-size: xx-small;">沒有</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARM</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;"> 32bits</span></span><span style="font-size: xx-small;">指令集</span><span style="font-size: xx-small;">豐富</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">但可以獲得比較高的程式碼密度</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">節省所需的記憶體空間</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">.</span></span></span></div>
<h4 id="14512_5-thumb2_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;">5, Thumb2</span></h4>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb2</span></span></span><span style="font-size: xx-small;">指令集提供了</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">16/32 bits</span></span></span><span style="font-size: xx-small;">版本的指令集</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-size: xx-small;">同樣是以根據</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">CPSR</span></span></span><span style="font-size: xx-small;">的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">T </span></span></span><span style="font-size: xx-small;">是否為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">1</span></span></span><span style="font-size: xx-small;">與</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">J</span></span></span><span style="font-size: xx-small;">是否為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">0,</span></span></span><span style="font-size: xx-small;">判定是否為</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb2 Mode.(</span></span></span><span style="font-size: xx-small;">所以處理器要支援哩</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">.), </span></span></span><span style="font-size: xx-small;">根據</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARM</span></span></span><span style="font-size: xx-small;">官網所述</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">(</span></span></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://www.arm.com/products/processors/technologies/instruction-set-architectures.php" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">http://www.arm.com/products/processors/technologies/instruction-set-architectures.php</span></span></a></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;"> ),Thumb-2 </span></span><span style="font-size: xx-small;">可以比</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARM Code</span></span></span><span style="font-size: xx-small;">減少</span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;"> </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">31%</span></span></span><span style="font-size: xx-small;">程式碼記憶體需求</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">, </span></span></span><span style="font-size: xx-small;">並且比原有的</span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb Code</span></span></span><span style="font-size: xx-small;">提升</span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;"> </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">38% </span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">的性能</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">. (</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">不同的測試代碼會有一些出入</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">.)</span></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">目前</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">像是</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Cortex M3,</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">就全面採用</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb2 Code,</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">而不支援</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARM</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">指令集</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">. </span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">以便得到相比</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">ARM</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">較低的程式碼記憶體需求</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">,</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">又得到較少的效能減損</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">(</span></span></span><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">相比</span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: arial, verdana, sans-serif;"><span style="font-size: xx-small;">Thumb Code).</span></span></span></div>
<h4 id="14512_6-thumb2-execution-e_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;">6, Thumb2 Execution Environment (Thumb-2EE)</span></h4>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
首先<span style="font-family: "Times New Roman", serif;">,</span>參考<span style="font-family: "Times New Roman", serif;">ARM</span>網頁<span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204ic/Cjafgdih.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204ic/Cjafgdih.html</a></span></span> “</span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">除非另有</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">說</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">明,否</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">則</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"> </span></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"><span style="text-decoration-line: underline;">ThumbEE </span></span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">指令</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">與</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"> </span></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"><span style="text-decoration-line: underline;">Thumb </span></span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">指令完全相</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">同</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">”</span></span></span><span style="font-family: "Times New Roman", serif;">,</span>從<span style="font-family: "Times New Roman", serif;">ARM</span>指令集的角度<span style="font-family: "Times New Roman", serif;">,</span>我們可以知道<span style="font-family: "Times New Roman", serif;">ThumbEE</span>跟既有<span style="font-family: "Times New Roman", serif;">Thumb</span>的指令是盡可能的一致<span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">開發端可以先進入</span><span style="font-family: "Times New Roman", serif;">Thumb Mode</span><span style="font-family: "Microsoft YaHei";">後</span><span style="font-family: "Times New Roman", serif;">(CPSR</span><span style="font-family: "Microsoft YaHei";">的</span><span style="font-family: "Times New Roman", serif;">T bit</span><span style="font-family: "Microsoft YaHei";">為</span><span style="font-family: "Times New Roman", serif;">1),</span><span style="font-family: "Microsoft YaHei";">再透過</span><span style="font-family: "Times New Roman", serif;">ENTERX</span><span style="font-family: "Microsoft YaHei";">指令</span><span style="font-family: "Times New Roman", serif;"><span style="text-decoration-line: underline;">(</span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">將</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"> </span></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"><span style="text-decoration-line: underline;">Thumb </span></span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">狀態</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">更改</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">為</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"> </span></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"><span style="text-decoration-line: underline;">ThumbEE </span></span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">狀態</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">,但</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">對</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"> </span></span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"><span style="text-decoration-line: underline;">ThumbEE </span></span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">狀態則</span></span></span><span style="text-decoration-line: underline;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">不起作用</span></span></span><span style="font-family: "Times New Roman", serif;"><span style="text-decoration-line: underline;">) </span></span><span style="font-family: "Microsoft YaHei";">進入</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode(CPSR</span><span style="font-family: "Microsoft YaHei";">的</span><span style="font-family: "Times New Roman", serif;">J bit</span><span style="font-family: "Microsoft YaHei";">為</span><span style="font-family: "Times New Roman", serif;">1) </span><span style="font-family: "Microsoft YaHei";">與透過</span><span style="font-family: "Times New Roman", serif;">LEAVEX</span><span style="font-family: "Microsoft YaHei";">指令</span><span style="font-family: "Times New Roman", serif;">(</span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">將</span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"> </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">ThumbEE </span></span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">狀態</span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">更改</span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">為</span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"> </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">Thumb </span></span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">狀態</span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">,但</span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">對</span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;"> </span></span><span style="font-family: "Times New Roman", serif;"><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">Thumb </span></span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">狀態則</span></span><span style="font-family: Verdana, Tahoma;"><span style="font-size: x-small;">不起作用</span></span><span style="font-family: "Microsoft YaHei";"> </span><span style="font-family: "Times New Roman", serif;">)</span><span style="font-family: "Microsoft YaHei";">離開</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode. ThumbEE Mode</span><span style="font-family: "Microsoft YaHei";">還提供如下指令集</span><span style="font-family: "Times New Roman", serif;">CHKA(</span><span style="font-family: "Microsoft YaHei";">檢查數組</span><span style="font-family: "Times New Roman", serif;">),HB</span><span style="font-family: "Microsoft YaHei";">、</span><span style="font-family: "Times New Roman", serif;">HBL</span><span style="font-family: "Microsoft YaHei";">、</span><span style="font-family: "Times New Roman", serif;">HBLP </span><span style="font-family: "Microsoft YaHei";">和 </span><span style="font-family: "Times New Roman", serif;">HBP(</span><span style="font-family: "Microsoft YaHei";">處理程序跳轉,跳轉到指定處理程序</span><span style="font-family: "Times New Roman", serif;">).</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Microsoft YaHei";">此外</span><span style="font-family: "Times New Roman", serif;">,</span>CP14有暫存器<span style="font-family: "Times New Roman", serif;">c0 </span>可供設定<span style="font-family: "Times New Roman", serif;">ThumbEE Configuration Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p14, 6, <Rd>, c0, c0, 0 ; Read ThumbEE Configuration Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p14, 6, <Rd>, c0, c0, 0 ; Write ThumbEE Configuration Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
也可透過設定<span style="font-family: "Times New Roman", serif;">ThumbEE HandlerBase Register,</span>支援當在<span style="font-family: "Times New Roman", serif;">ThumbEE</span>發生例外時<span style="font-family: "Times New Roman", serif;">,</span>可以讓應用程式有機會修正處理</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p14, 6, <Rd>, c1, c0, 0 ; Read ThumbEE HandlerBase Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p14, 6, <Rd>, c1, c0, 0 ; Write ThumbEE HandlerBase Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Microsoft YaHei";">開發階段</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">可以透過設定</span><span style="font-family: "Times New Roman", serif;">THUMBX</span><span style="font-family: "Microsoft YaHei";">程式碼節區</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">把指令集編譯為</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode(</span><span style="font-family: "Microsoft YaHei";">可以參考</span><span style="font-family: "Times New Roman", serif;"><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204ic/CIHBCDGA.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204ic/CIHBCDGA.html</a></span></span> ),</span><span style="font-family: "Microsoft YaHei";">筆者撰寫如下參考程式碼</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">AREA ToThumbX, CODE, READONLY</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ENTRY</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">start</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRS R0,CPSR</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BIC R0,R0,#0x1F</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ORR R0,R0,#0x10 ;Switch to User Mode.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MSR CPSR_c,R0</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOVS R1,#0x7000 ; handler_ThumbEE =0x7000-4</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p14, 6, R1, c1, c0, 0 ; Write ThumbEE HandlerBase Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ADR r0, enter_Thumb + 1</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">BX r0 ;</span><span style="font-family: "Microsoft YaHei";">進入</span><span style="font-family: "Times New Roman", serif;">Thumb Mode</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">THUMB</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">enter_Thumb</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">NOP</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ENTERX ;</span><span style="font-family: "Microsoft YaHei";">進入</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">THUMBX</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">enter_ThumbX</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOVS R2, #2 ; Load R2 with value 2.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOV.W R3, #3 ; Load R3 with value 3. =>32bits Thumb2 </span><span style="font-family: "Microsoft YaHei";">指令</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ADDS R2, R2, R3 ; R2 = R2 + R3</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOVS r0,#0 ;char *p; and p=0;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOVS r1,#2</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">STRB r1,[r0,#0] ;*p=2; =></span><span style="font-family: "Microsoft YaHei";">觸發</span><span style="font-family: "Times New Roman", serif;">Data Abort.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MOVS r0,#1</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">LEAVEX ;</span><span style="font-family: "Microsoft YaHei";">離開</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">THUMB</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">leave_ThumbX</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">NOP</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">END</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Microsoft YaHei";">並請以支援</span><span style="font-family: "Times New Roman", serif;">Cortex-A8</span><span style="font-family: "Microsoft YaHei";">指令集的編譯器版本進行如下編譯</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">armcc –cpu=Cortex-A8 thumbee.s -o thumbee.elf</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們把 <span style="font-family: "Times New Roman", serif;">handler_ThumbEE</span><span style="font-family: "Microsoft YaHei";">設定為</span><span style="font-family: "Times New Roman", serif;">0x7000,</span><span style="font-family: "Microsoft YaHei";">透過</span><span style="font-family: "Times New Roman", serif;">CP14</span><span style="font-family: "Microsoft YaHei";">設定</span><span style="font-family: "Times New Roman", serif;">ThumbEE HandlerBase Register,</span><span style="font-family: "Microsoft YaHei";">隨後程式碼執行</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">從</span><span style="font-family: "Times New Roman", serif;">SVC Mode</span><span style="font-family: "Microsoft YaHei";">切到</span><span style="font-family: "Times New Roman", serif;">User Mode,</span><span style="font-family: "Microsoft YaHei";">之後進入</span><span style="font-family: "Times New Roman", serif;">Thumb Mode,</span><span style="font-family: "Microsoft YaHei";">然後透過</span><span style="font-family: "Times New Roman", serif;">ENTERX</span><span style="font-family: "Microsoft YaHei";">進入</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode,</span><span style="font-family: "Microsoft YaHei";">首先驗證</span><span style="font-family: "Times New Roman", serif;">16bits</span><span style="font-family: "Microsoft YaHei";">與</span><span style="font-family: "Times New Roman", serif;">32bits Thumb2</span><span style="font-family: "Microsoft YaHei";">指令集在</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode</span><span style="font-family: "Microsoft YaHei";">下的支援無誤</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">之後刻意產生一個</span><span style="font-family: "Times New Roman", serif;">NULL Pointer</span><span style="font-family: "Microsoft YaHei";">的</span><span style="font-family: "Times New Roman", serif;">Data Abort,</span><span style="font-family: "Microsoft YaHei";">在</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode</span><span style="font-family: "Microsoft YaHei";">下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">會直接把</span><span style="font-family: "Times New Roman", serif;">PC</span><span style="font-family: "Microsoft YaHei";">值只到</span><span style="font-family: "Times New Roman", serif;">0x7000-4</span><span style="font-family: "Microsoft YaHei";">的記憶體位址</span><span style="font-family: "Times New Roman", serif;">, </span><span style="font-family: "Microsoft YaHei";">執行我們安排好的處理函式</span><span style="font-family: "Times New Roman", serif;">. </span><span style="font-family: "Microsoft YaHei";">在處理函式中我們可以發現處理器還是處於</span><span style="font-family: "Times New Roman", serif;">User Mode(</span><span style="font-family: "Microsoft YaHei";">模式並沒有轉換</span><span style="font-family: "Times New Roman", serif;">),</span><span style="font-family: "Microsoft YaHei";">同時指令及模式還是處於</span><span style="font-family: "Times New Roman", serif;">ThumbEE Mode.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Microsoft YaHei";">透過基礎的驗證</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">我們知道在</span><span style="font-family: "Times New Roman", serif;">ThumbEE</span><span style="font-family: "Microsoft YaHei";">模式下</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">發生異常處理時</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">會導引到</span><span style="font-family: "Times New Roman", serif;">ThumbEE Handler</span><span style="font-family: "Microsoft YaHei";">中</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">透過該</span><span style="font-family: "Times New Roman", serif;">Handler</span><span style="font-family: "Microsoft YaHei";">應用程式可以有機會進行補救措施</span><span style="font-family: "Times New Roman", serif;">,</span><span style="font-family: "Microsoft YaHei";">而不適直接觸發處理器等級的</span><span style="font-family: "Times New Roman", serif;">Abort,</span><span style="font-family: "Microsoft YaHei";">導致應用程式直接終止執行</span><span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
舉個我們在<span style="font-family: "Times New Roman", serif;">Windows</span>環境設定<span style="font-family: "Times New Roman", serif;">SEH(Structured Exception Handling)</span>的例子來說明<span style="font-family: "Times New Roman", serif;">,</span>應用程式可以透過如下的程式碼設定<span style="font-family: "Times New Roman", serif;">Windows</span>上的<span style="font-family: "Times New Roman", serif;">SEH</span>處理程式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">handler = (DWORD) problem_fixing_seh ;</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">__asm{</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mov eax,handler</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">push eax</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">push fs:0</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">mov fs:0,esp</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">};</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
只要在應用程式啟動時<span style="font-family: "Times New Roman", serif;">,</span>預先把<span style="font-family: "Times New Roman", serif;">SEH</span>設定好<span style="font-family: "Times New Roman", serif;">,</span>如果應用程式因為設計不當<span style="font-family: "Times New Roman", serif;">,</span>導致記憶體錯誤而中斷<span style="font-family: "Times New Roman", serif;">,</span>就有機會先跳到處理函式 <span style="font-family: "Times New Roman", serif;">problem_fixing_seh</span>中<span style="font-family: "Times New Roman", serif;">,</span>我們再透過這個函式把發生問題當下的現場包括暫存器<span style="font-family: "Times New Roman", serif;">,Stack</span>與必要的資訊記錄下來<span style="font-family: "Times New Roman", serif;">,</span>就有機會可以透過這些資訊幫助應用程式開發者把問題解決<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對應到有<span style="font-family: "Times New Roman", serif;">MMU</span>環境<span style="font-family: "Times New Roman", serif;">,</span>且有區分<span style="font-family: "Times New Roman", serif;">User Mode</span>與<span style="font-family: "Times New Roman", serif;">Kernel Mode</span>應用程式的消費性電子產品開發<span style="font-family: "Times New Roman", serif;">,ThumbEE</span>可以讓應用程式在啟動時設定好<span style="font-family: "Times New Roman", serif;">ThumbEE Handler,</span>如果應用程式因為不當設計而導致錯誤<span style="font-family: "Times New Roman", serif;">,</span>就可以讓開發者有機會透過<span style="font-family: "Times New Roman", serif;">Handler</span>把錯誤現場資訊蒐集下來<span style="font-family: "Times New Roman", serif;">,</span>甚至也可以透過通訊機制回傳<span style="font-family: "Times New Roman", serif;">,</span>幫助開發者收斂問題<span style="font-family: "Times New Roman", serif;">.(</span>當然<span style="font-family: "Times New Roman", serif;">,</span>應用程式有能力自己把問題排除會是更好的<span style="font-family: "Times New Roman", serif;">.)</span></div>
<h4 id="14512_7-vfp-vector-floatin_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
<span style="font-family: "Times New Roman", serif;">7, </span><span style="font-family: "Times New Roman", serif;">VFP</span><span style="font-family: "Times New Roman", serif;"> </span><span style="font-family: "Times New Roman", serif;">(Vector Floating Point) </span>與 <span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Advanced SIMD (NEON)</span></span></h4>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>處理器把向量浮點放到<span style="font-family: "Times New Roman", serif;">Coprocessor</span>處理<span style="font-family: "Times New Roman", serif;">,</span>可以提供經濟的單精度與倍精度浮點運算能力<span style="font-family: "Times New Roman", serif;">,</span>並可相容於<span style="font-family: "Times New Roman", serif;">ANSI/IEEE Std 754-1985 </span>二進位浮點算數標準<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>的<span style="font-family: "Times New Roman", serif;">Advanced SIMD (NEON)</span>指令集<span style="font-family: "Times New Roman", serif;">,</span>也就是我們所稱的<span style="font-family: "Times New Roman", serif;">NEON,</span>提供了<span style="font-family: "Times New Roman", serif;">64</span>或<span style="font-family: "Times New Roman", serif;">128bits</span>的<span style="font-family: "Times New Roman", serif;">SIMD</span>(<span style="font-family: "Times New Roman", serif;">Single Instruction Multiple Data</span>)指令集<span style="font-family: "Times New Roman", serif;">,</span>可以針對多媒體的應用提供指令集的加速能力<span style="font-family: "Times New Roman", serif;">,NEON</span>本身是基於<span style="font-family: "Times New Roman", serif;">Coprocessor 10</span>與<span style="font-family: "Times New Roman", serif;">11</span>所提供的指令集<span style="font-family: "Times New Roman", serif;">,Coprocessor</span>有自己的暫存器<span style="font-family: "Times New Roman", serif;">,</span>指令集<span style="font-family: "Times New Roman", serif;">,</span>與獨立執行的處理器單元<span style="font-family: "Times New Roman", serif;">,NEON</span>支援<span style="font-family: "Times New Roman", serif;">8/16/32/64bits</span>的整數與<span style="font-family: "Times New Roman", serif;">32bits</span>單經度浮點運算<span style="font-family: "Times New Roman", serif;">,</span>在<span style="font-family: "Times New Roman", serif;">NEON</span>中<span style="font-family: "Times New Roman", serif;">,SIMD</span>最高可以執行到<span style="font-family: "Times New Roman", serif;">16</span>個運算<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">有關</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NEON</span></span><span style="font-size: x-small;">的效能比較</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">建議可以參考 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM Architecture & NEON(</span></span><span style="color: blue;"><span style="text-decoration-line: underline;"><a href="http://www.stanford.edu/class/ee282/handouts/lect.10.arm_soc.4pp.pdf" style="color: #666666; font-weight: bold; text-decoration-line: none;"><span style="font-size: x-small;">http://www.stanford.edu/class/ee282/handouts/lect.10.arm_soc.4pp.pdf</span></a></span></span><span style="font-size: x-small;">)</span><span style="font-size: x-small;">這份文件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">其中也包含了跟</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ATOM N270</span></span><span style="font-size: x-small;">的比較</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,NEON</span></span><span style="font-size: x-small;">支援</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">64bits</span></span><span style="font-size: x-small;">長度的暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">D0-D31)</span></span><span style="font-size: x-small;">或可用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Q</span></span><span style="font-size: x-small;">暫存器的方式使用為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">128bits</span></span><span style="font-size: x-small;">長度的暫存器</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">為</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Q0-Q15),</span></span><span style="font-size: x-small;">一個暫存器在處理多媒體資料時</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">最多可以儲存</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">4</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">32bits</span></span><span style="font-size: x-small;">浮點數</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">或是</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">16</span></span><span style="font-size: x-small;">個</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">signed</span></span><span style="font-size: x-small;">字元</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">以</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">文件中所舉的 </span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">AAC</span></span><span style="font-size: x-small;">編碼中所用到的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FFT(Fast Fourier Transform)</span></span><span style="font-size: x-small;">算法來說</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">只用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARMv6 SIMD</span></span><span style="font-size: x-small;">指令根用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARMv7 NEON</span></span><span style="font-size: x-small;">指令可以差到約四倍的執行效率</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">,</span></span><span style="font-size: x-small;">在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ffmpeg</span></span><span style="font-size: x-small;">中的</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FFT</span></span><span style="font-size: x-small;">也可達到約</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">12</span></span><span style="font-size: x-small;">倍的效率</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">(</span></span><span style="font-size: x-small;">僅供參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.).</span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: x-small;">要使用</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">NEON,</span></span><span style="font-size: x-small;">可以直接在</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">armcc</span></span><span style="font-size: x-small;">編譯時加上—</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">vectorize,</span></span><span style="font-size: x-small;">其他參數還請參考</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">ARM</span></span><span style="font-size: x-small;">編譯器的文件</span><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">.</span></span></div>
<h4 id="14512_8-security-extension_1" style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 19px; margin: 1.33em 0px 0.2em; padding-bottom: 0px; padding-top: 0px;">
8, Security Extensions (TrustZone)</h4>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
提到<span style="font-family: "Times New Roman", serif;">TrustZone,</span>其實在<span style="font-family: "Times New Roman", serif;">PC</span>產業也有安全運算組織<span style="font-family: "Times New Roman", serif;">TCG(http://www.trustedcomputinggroup.org/)</span>在致力於推動這類平台安全的機制<span style="font-family: "Times New Roman", serif;">,</span>並制定了像是<span style="font-family: "Times New Roman", serif;">TPM(Trusted Platform Module)</span>與運行在其上的軟體架構<span style="font-family: "Times New Roman", serif;">TCG Software Stack,</span>讓電腦環境的應用程式或核心驅動程式也區分<span style="font-family: "Times New Roman", serif;">Trusted</span>與<span style="font-family: "Times New Roman", serif;">Non-Trusted</span>的執行環境<span style="font-family: "Times New Roman", serif;">,</span>包括新的<span style="font-family: "Times New Roman", serif;">Windows</span>環境<span style="font-family: "Times New Roman", serif;">,</span>與<span style="font-family: "Times New Roman", serif;">Linux Kernel 2.6</span>之後也有支援<span style="font-family: "Times New Roman", serif;">,</span>可以透過<span style="font-family: "Times New Roman", serif;">make menuconfig</span>中進入<span style="font-family: "Times New Roman", serif;">Device Drivers —> Character devices —>[*] TPM Hardware Support </span>根據平台上支援的<span style="font-family: "Times New Roman", serif;">TPM </span>介面選擇 <span style="font-family: "Times New Roman", serif;">National Semiconductor TPM Interface </span>或 <span style="font-family: "Times New Roman", serif;">Atmel TPM Interface (</span>會根據所取得的<span style="font-family: "Times New Roman", serif;">Linux Kernel</span>版本而有所不同<span style="font-family: "Times New Roman", serif;">.)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前微軟作業系統中也有支援基於<span style="font-family: "Times New Roman", serif;">TPM</span>技術的<span style="font-family: "Times New Roman", serif;">BitLocker(</span>參考網址<span style="font-family: "Times New Roman", serif;">http://windows.microsoft.com/zh-TW/windows7/Learn-more-about-BitLocker-Drive-Encryption),</span>如果<span style="font-family: "Times New Roman", serif;">TPM</span>偵測到作業系統磁碟啟動檔案被改變<span style="font-family: "Times New Roman", serif;">,</span>就會強制進入修復模式<span style="font-family: "Times New Roman", serif;">,</span>必須要輸入修復密碼才能重新正確的讀取資料<span style="font-family: "Times New Roman", serif;">,</span>或如果發現<span style="font-family: "Times New Roman", serif;">TPM</span>資料跟不一致<span style="font-family: "Times New Roman", serif;">,</span>也會強制要求輸入修復密碼<span style="font-family: "Times New Roman", serif;">.Windows TPM</span>機制也可以提供搭配啟動金鑰或<span style="font-family: "Times New Roman", serif;">PIN</span>碼的機制<span style="font-family: "Times New Roman", serif;">,</span>如果使用者的筆記電腦不小心遺失<span style="font-family: "Times New Roman", serif;">,</span>而第三者如果沒有匹配具有對應加密金鑰的<span style="font-family: "Times New Roman", serif;">USB</span>磁碟或是沒有輸入正確的<span style="font-family: "Times New Roman", serif;">PIN</span>碼<span style="font-family: "Times New Roman", serif;">,</span>也會無法順利地開啟作業系統磁碟的資料<span style="font-family: "Times New Roman", serif;">. </span>在<span style="font-family: "Times New Roman", serif;">windows</span>電腦上<span style="font-family: "Times New Roman", serif;">,</span>基於<span style="font-family: "Times New Roman", serif;">TPM</span>我們可以做到避免重要資料的磁碟被刻意拔到其他電腦上讀取<span style="font-family: "Times New Roman", serif;">,</span>的資料遺失風險<span style="font-family: "Times New Roman", serif;">,</span>就算是電腦被第三方使用者盜取<span style="font-family: "Times New Roman", serif;">,</span>也可以有效確保資料遺失的風險<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">TrustZone</span>是由<span style="font-family: "Times New Roman", serif;">ARM</span>所提出在處理器架構上<span style="font-family: "Times New Roman", serif;">,</span>區分<span style="font-family: "Times New Roman", serif;">Secure</span>與<span style="font-family: "Times New Roman", serif;">Non-Secure</span>模式的兩個平行執行環境 <span style="font-family: "Times New Roman", serif;">(Secure World </span>與 <span style="font-family: "Times New Roman", serif;">Normal World),</span>這兩個執行環境可以透過<span style="font-family: "Times New Roman", serif;">Secure Monitor Mode</span>來進行切換<span style="font-family: "Times New Roman", serif;">,</span>概念如下所示</div>
<dl style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;">
<dl style="margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;">
<dl style="margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;">
<dl style="margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;">
<dl style="margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;"><dd><table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0" style="border-collapse: collapse; font-size: 1em; margin: 10px 0px; width: 448px;"><colgroup><col width="154"></col><col width="81"></col><col width="181"></col></colgroup><tbody>
<tr valign="TOP"><td bgcolor="#23b8dc" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">Non-Secure</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">User Mode<br />(Application)</span></div>
</td><td rowspan="2" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="81"></td><td bgcolor="#ff420e" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;">Secure</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">User Mode<br />(Application)</span></div>
</td></tr>
<tr class="alt" valign="TOP"><td bgcolor="#23b8dc" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="154"><span style="font-family: "Times New Roman", serif;">Non-Secure</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Privileged Mode<br />(Kernel/Driver)</span></div>
</td><td bgcolor="#ff420e" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="181"><span style="font-family: "Times New Roman", serif;">Secure</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">Privileged Mode<br />(Kernel/Driver)</span></div>
</td></tr>
<tr><td colspan="3" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="TOP" width="436"><span style="font-family: "Times New Roman", serif;">Monitor Mode (Exception)</span></td></tr>
</tbody></table>
</dd></dl>
</dl>
</dl>
</dl>
</dl>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於<span style="font-family: "Times New Roman", serif;">TrustZone,</span>不屬於<span style="font-family: "Times New Roman", serif;">Secure</span>區域的應用程式或是核心程式<span style="font-family: "Times New Roman", serif;">,</span>就會無法存取屬於<span style="font-family: "Times New Roman", serif;">Secure</span>區域的資料<span style="font-family: "Times New Roman", serif;">,</span>可用來確保在<span style="font-family: "Times New Roman", serif;">SmartPhone</span>這類產品上<span style="font-family: "Times New Roman", serif;">,</span>因為下載第三方惡意程式所帶來的安全問題<span style="font-family: "Times New Roman", serif;">. TtrustZone</span>中有關的軟體安全機制<span style="font-family: "Times New Roman", serif;">,</span>是由<span style="font-family: "Times New Roman", serif;">Trusted Logic S.A.</span>這家公司所共同研發的<span style="font-family: "Times New Roman", serif;">,</span>在一個支援<span style="font-family: "Times New Roman", serif;">TrustZone</span>的處理器上<span style="font-family: "Times New Roman", serif;">,</span>會有一塊記憶體空間預留給專屬<span style="font-family: "Times New Roman", serif;">Secure Mode</span>的應用程式或是核心程式執行<span style="font-family: "Times New Roman", serif;">,</span>也因此<span style="font-family: "Times New Roman", serif;">,MMU</span>也必須要能支援這樣的欄位<span style="font-family: "Times New Roman", serif;">.(</span>因此像是<span style="font-family: "Times New Roman", serif;">ARM1176</span>或是 <span style="font-family: "Times New Roman", serif;">Cortex A</span>這類有<span style="font-family: "Times New Roman", serif;">MMU</span>的處理器環境會非常適合<span style="font-family: "Times New Roman", serif;">). </span>基於此<span style="font-family: "Times New Roman", serif;">,</span>才能透過記憶體管理機制<span style="font-family: "Times New Roman", serif;">,</span>在硬體上實際的分割出<span style="font-family: "Times New Roman", serif;">Secure</span>與<span style="font-family: "Times New Roman", serif;">Non-Secure</span>的記憶體執行與使用空間<span style="font-family: "Times New Roman", serif;">,</span>避免<span style="font-family: "Times New Roman", serif;">Non-Secure</span>應用的惡意越界<span style="font-family: "Times New Roman", serif;">. </span>根據<span style="font-family: "Times New Roman", serif;">ARM</span>的資料<span style="font-family: "Times New Roman", serif;">,</span>一個可供執行的<span style="font-family: "Times New Roman", serif;">TrustZone</span>環境必須包括</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">A. </span>支援 <span style="font-family: "Times New Roman", serif;">TrustZone </span>的處理器</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">B. </span>晶片上的<span style="font-family: "Times New Roman", serif;">Boot Rom</span>用來支援啟動時的安全設定<span style="font-family: "Times New Roman", serif;">. (</span>透過外部<span style="font-family: "Times New Roman", serif;">Flash</span>儲存<span style="font-family: "Times New Roman", serif;">BootCode</span>會有被修改的風險<span style="font-family: "Times New Roman", serif;">.)</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">C. </span>晶片上可供用來儲存設定或主控密碼的空間 <span style="font-family: "Times New Roman", serif;">(Maybe OTP(One Time Programmable))</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">D. </span>支援<span style="font-family: "Times New Roman", serif;">On-Chip RAM</span>用來儲存<span style="font-family: "Times New Roman", serif;">DRM</span>或相關重要的密碼資訊</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">E. </span>能夠設定成只限定被信任的應用軟體使用的周邊<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">ARM</span>會提供由<span style="font-family: "Times New Roman", serif;">Trusted Logic S.A.</span>所提供的安全模組<span style="font-family: "Times New Roman", serif;">,</span>支援跟<span style="font-family: "Times New Roman", serif;">TrustZone</span>行為一致的安全保密協議<span style="font-family: "Times New Roman", serif;">.</span>通過這些軟體保密服務<span style="font-family: "Times New Roman", serif;">,</span>所提供的安全檢查<span style="font-family: "Times New Roman", serif;">,ARM</span>希望能支援像是<span style="font-family: "Times New Roman", serif;">SIM</span>卡上鎖<span style="font-family: "Times New Roman", serif;">,IMEI</span>保密<span style="font-family: "Times New Roman", serif;">,</span>安全啟動<span style="font-family: "Times New Roman", serif;">(</span>確保所要載入的作業系統核心沒有被修改過<span style="font-family: "Times New Roman", serif;">.)(OMTP -Open Mobile Terminal Platform,</span>也有制定相關<span style="font-family: "Times New Roman", serif;">Secure Boot</span>的需求<span style="font-family: "Times New Roman", serif;">),DRM (Digital Right Management)</span>受版權保護的資料內容<span style="font-family: "Times New Roman", serif;">,</span>數位簽名與電子銀行<span style="font-family: "Times New Roman", serif;">. </span>參考<span style="font-family: "Times New Roman", serif;">ARM</span>的文件<span style="font-family: "Times New Roman", serif;">,ARM</span>會提供有包括<span style="font-family: "Times New Roman", serif;">,Trusted Interpreter,TrustZone Access Driver, TrustZone Monitor,Secure Kernel,Secure Key Storage,SIM Lock,E-Wallet </span>與 <span style="font-family: "Times New Roman", serif;">API Framework </span>這些配套的軟體模組<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">SMI(Software Monitor Instruction,</span>安全稽核<span style="font-family: "Times New Roman", serif;">(</span>監察<span style="font-family: "Times New Roman", serif;">)</span>中斷<span style="font-family: "Times New Roman", serif;">)</span>跟<span style="font-family: "Times New Roman", serif;">SMC</span>兩者的機械碼指令是一致的<span style="font-family: "Times New Roman", serif;">,</span>都會透過<span style="font-family: "Times New Roman", serif;">SVC</span>的中斷觸發<span style="font-family: "Times New Roman", serif;">,</span>讓<span style="font-family: "Times New Roman", serif;">Non-Secure</span>的程式碼有機會可以透過<span style="font-family: "Times New Roman", serif;">Monitor Mode</span>切到<span style="font-family: "Times New Roman", serif;">Secure State. </span>如下所示<span style="font-family: "Times New Roman", serif;">,</span>透過<span style="font-family: "Times New Roman", serif;">TrustZone,</span>我們可以設定<span style="font-family: "Times New Roman", serif;">Asynchronous Abort,IRQ,FIQ,DMA,TLB,Coprocessor </span>等周邊中斷與管理單元是否都要納入<span style="font-family: "Times New Roman", serif;">Secure State</span>的管理中<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>Secure Configuration Register (SCR)</strong></span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 913px;"><colgroup><col width="100"></col><col width="161"></col><col width="638"></col></colgroup><tbody>
<tr class="alt" valign="TOP"><td height="23" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">位元</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161">功能</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638">說明</td></tr>
<tr valign="TOP"><td height="27" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">31 – 7</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">UNK/SBZP</span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">(Bits [31:7])</span></div>
</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">UNK/SBZP</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">unknown on reads, Should-Be-Zero-or-Preserved on writes.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">6</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">nET</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Not Early Termination. This bit disables early termination</span></span></td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">5</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">AW</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">A bit writable. This bit controls whether the A bit in the CPSR can be modified in Non-secure state:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 the CPSR.A bit can be modified only in Secure state.</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 the CPSR.A bit can be modified in any security state.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">FW</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">F bit writable. This bit controls whether the F bit in the CPSR can be modified in Non-secure state:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 the CPSR.F bit can be modified only in Secure state</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 the CPSR.F bit can be modified in any security state.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">3</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">EA</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">External Abort handler. This bit controls which mode handles external aborts:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 Abort mode handles external aborts</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 Monitor mode handles external aborts.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">2</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">FIQ</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">FIQ handler. This bit controls which mode the processor enters when a Fast Interrupt (FIQ) is taken:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 FIQ mode entered when FIQ is taken</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 Monitor mode entered when FIQ is taken.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">IRQ</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">IRQ handler. This bit controls which mode the processor enters when an Interrupt (IRQ) is taken:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 IRQ mode entered when IRQ is taken</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 Monitor mode entered when IRQ is taken.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="13" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">NS</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Non Secure bit. Except when the processor is in Monitor mode, this bit determines the security state of the processor.</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 =Secure state</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 =Non-secure state</span></span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並可以透過如下程式碼修改<span style="font-family: "Times New Roman", serif;">Secure Configuration Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p15,0,<Rt>,c1,c1,0 ; Read CP15 Secure Configuration Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p15,0,<Rt>,c1,c1,0 ; Write CP15 Secure Configuration Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><strong>Non-Secure Access Control Register</strong></span></div>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 913px;"><colgroup><col width="100"></col><col width="161"></col><col width="638"></col></colgroup><tbody>
<tr valign="TOP"><td height="23" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100">位元</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161">功能</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638">說明</td></tr>
<tr class="alt" valign="TOP"><td height="27" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">31 – 19</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">SBZ</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">SBZ</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Should-Be-Zero on writes.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">18</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">DMA</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Reserves the DMA channels and registers for the Secure world and determines the page tables, Secure or Non-Secure, to use for DMA transfers.</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = DMA reserved for the Secure world only and the Secure page tables are used for DMA transfers,reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = DMA can be used by the Non-Secure world and the Non-Secure page tables are used for DMAtransfers.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">17</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">TL</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Prevents operations in the Non-Secure world from locking page tables in TLB lockdown entries.</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">The Invalidate Single Entry or Invalidate ASID match operations can match a TLB lockdown entry but an Invalidate All operation only applies to unlocked entries:</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Reserve TLB Lockdown registers for Secure operation only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = TLB Lockdown registers available for Secure and Non-Secure operation.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">16</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CL</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Prevents operations in the Non-Secure world from changing cache lockdown entries:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Reserve cache lockdown registers for Secure operation only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Cache lockdown registers available for Secure and Non-Secure operation.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">15 – 14</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">SBZ</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">SBZ</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Should-Be-Zero on writes.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">13</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP13</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">12</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP12</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">11</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP11</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">10</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP10</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">9</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP9</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">8</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP8</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">7</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP7</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">6</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP6</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">5</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP5</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP4</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">3</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP3</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="14" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">2</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP2</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr valign="TOP"><td height="14" style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP1</span></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
<tr class="alt" valign="TOP"><td height="13" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="100"><span style="font-family: "Times New Roman", serif;">0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="161"><span style="font-family: "Times New Roman", serif;">CP0</span></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" width="638"><span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">Determines permission to access the given coprocessor in the Non-Secure world:</span></span><div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">0 = Secure access only, reset value</span></span></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;"><span style="font-size: x-small;">1 = Secure or Non-Secure access.</span></span></div>
</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
並可以透過如下程式碼修改<span style="font-family: "Times New Roman", serif;">Non-Secure Access Control Register</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MRC p15, 0, <Rd>, c1, c1, 2 ; Read Non-Secure Access Control Register data</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-family: "Times New Roman", serif;">MCR p15, 0, <Rd>, c1, c1, 2 ; Write Non-Secure Access Control Register data</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
當處理器處於<span style="font-family: "Times New Roman", serif;">Monitor Mode (CPSR M[4:0] = b10110),</span>處理器就是位於<span style="font-family: "Times New Roman", serif;">Secure State,</span>這時對<span style="font-family: "Times New Roman", serif;">CP15</span>的讀寫<span style="font-family: "Times New Roman", serif;">(MRC and MCR)</span>動作<span style="font-family: "Times New Roman", serif;">,</span>就會根據<span style="font-family: "Times New Roman", serif;">SCR.NS bit</span>的值<span style="font-family: "Times New Roman", serif;">,</span>如果<span style="font-family: "Times New Roman", serif;">NS(Non-Secure)</span>為<span style="font-family: "Times New Roman", serif;">0,</span>就是處於<span style="font-family: "Times New Roman", serif;">Secure State</span>狀態<span style="font-family: "Times New Roman", serif;">,</span>對暫存器的讀寫就是透過<span style="font-family: "Times New Roman", serif;">Secure Banked</span>暫存器<span style="font-family: "Times New Roman", serif;">,</span>如果<span style="font-family: "Times New Roman", serif;">NS</span>為<span style="font-family: "Times New Roman", serif;">1,</span>就是處於<span style="font-family: "Times New Roman", serif;">Non-Secure State</span>狀態<span style="font-family: "Times New Roman", serif;">,</span>讀寫的暫存器就是<span style="font-family: "Times New Roman", serif;">Non-Secure Banked</span>暫存器<span style="font-family: "Times New Roman", serif;">.</span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<span style="font-size: small;"><strong>暫告段落</strong></span><span style="font-family: "Times New Roman", serif;"><span style="font-size: small;"><strong>.</strong></span></span></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
其實<span style="font-family: "Times New Roman", serif;">,</span>行筆至此<span style="font-family: "Times New Roman", serif;">,</span>感覺要寫的東西真的太多了<span style="font-family: "Times New Roman", serif;">…@_@..,</span>既然是筆記<span style="font-family: "Times New Roman", serif;">,</span>那就是隨筆去寫<span style="font-family: "Times New Roman", serif;">,</span>暫時先做一個段落<span style="font-family: "Times New Roman", serif;">,</span>之後有空<span style="font-family: "Times New Roman", serif;">,</span>再寫下一回的<span style="font-family: "Times New Roman", serif;">ARM</span>與<span style="font-family: "Times New Roman", serif;">Cortex</span>筆記吧<span style="font-family: "Times New Roman", serif;">.</span></div>
</div>
<div>
<span style="font-family: "Times New Roman", serif;"><br /></span></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-44717842413317246982017-06-01T09:49:00.000-07:002017-06-01T09:49:19.968-07:00Android筆記.<h1 style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 34px; line-height: 1.2; margin: 0px; padding: 0px;">
Android筆記.</h1>
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android筆記.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px; text-align: right;">
<a href="mailto:hlchou@mail2000.com.tw" style="color: #666666; font-weight: bold; text-decoration-line: none;">hlchou@mail2000.com.tw</a>by loda</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有好一段時間,都在ARM based RTOS通訊產品中開發,很難有機會回到Embedded Linux的領域,而Linux上所擁有的豐富資源,更是凡事都要親力親為的RTOS環境所不能比擬的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
最近,有機會參與移植Android到新的晶片計畫,也藉此機會,把Android的基礎工程做一個Review.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在平台正式取得前,我們可以透過QEMU的環境模擬出Google定義的goldfish處理器平台(核心為ARM926EJ-S ARMv5TEJ),並可以透過git://android.git.kernel.org/kernel/common.git下載Linux Kernel,編譯出基於這個處理器的核心Image.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
而在編譯Android環境時,可以加上 showcommands的參數,幫助我們了解Android編譯過程所進行的相關動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
本文僅供參考,隨著Android未來的版本迭替可能內容會有所差異,還請以當時所取得的Android環境為依據.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前所整理的Android內容差異包括</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,Android</strong><strong>所屬的</strong><strong>Linux</strong><strong>核心模組</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>A, Ashmem (Anonymous Shared Memory)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
主要用來提供跨行程的共享記憶體配置,跟PMEM差異在於,PMEM必須在核心中預先把記憶體先規劃出來一塊連續的實體記憶體,專屬於PMEM使用,Ashmem無須事先在核心中設定,可以根據需求動態的配置出來,是屬於虛擬記憶體空間中連續的一塊記憶體,對應到實體記憶體空間可能是不同的區塊.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
有在Win32環境下開發人應該對於透過CreateFileMapping/MapViewOfFile產生Shared Memory的機制不陌生,Win32兩個行程可以透過開啟同一個Shared Memory物件的路徑,達成跨行程共享記憶體的目的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
同樣的,在Android應用程式的開發中也可以透過MemoryFile使用Shared Memory物件.如下範例</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
import android.os.MemoryFile;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
MemoryFile vMemoryFile;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
try {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vMemoryFile = new MemoryFile(“SharedMemory”, 256);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
byte[] vTmpW = new byte[256];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
for (int i = 0; i < 255; i++) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vTmpW[i] = (byte) i;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vMemoryFile.writeBytes(vTmpW, 0, 0, vTmpW.length);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
byte[] vTmpR = new byte[256];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vMemoryFile.readBytes(vTmpR, 0, 0, vTmpR.length);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vMemoryFile.close();</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} catch (IOException e) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
// TODO Auto-generated catch block</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
e.printStackTrace();</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
核心的Ashmem會在 devfs中註冊一個 ashmem,用來做為對應上層的操作介面,並且有制定以下的IO Control命令,讓管理機制可以施行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
(Source Code in bionic\libc\kernel\common\linux\ashmem.h)</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="264">IO Control 命令</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="252">功能</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="264">ASHMEM_SET_NAME</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="252">設定Shared Memory物件名稱</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="264">ASHMEM_SET_SIZE</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="252">設定Shared Memory區塊大小</td></tr>
<tr class=""><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="264">ASHMEM_GET_SIZE</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="252">取得Shared Memory區塊大小</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="264">ASHMEM_PIN</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="252">設定這區塊在記憶體不足時,不被回收</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="264">ASHMEM_UNPIN</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="252">設定這區塊在記憶體不足時,可以被回收</td></tr>
<tr class="alt"><td colspan="2" style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="516">ASHMEM_GET_NAME, ASHMEM_SET_PROT_MASK, ASHMEM_GET_PROT_MASK, ASHMEM_GET_PIN_STATUS, ASHMEM_PURGE_ALL_CACHES…etc</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考system\core\libcutils\ashmem-dev.c中有關ashmem_create_region函式的實作</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define ASHMEM_DEVICE “/dev/ashmem”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int ashmem_create_region(const char *name, size_t size)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int fd, ret;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fd = open(ASHMEM_DEVICE, O_RDWR);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (fd < 0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return fd;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (name) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char buf[ASHMEM_NAME_LEN];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
strlcpy(buf, name, sizeof(buf));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ioctl(fd, ASHMEM_SET_NAME, buf);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (ret < 0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
goto error;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = ioctl(fd, ASHMEM_SET_SIZE, size);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (ret < 0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
goto error;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return fd;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
error:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
close(fd);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ret;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
應用程式使用Ashmem作為Shared Memory的作法,也跟一般Linux應用程式透過mmap的作法一樣,只是他有額外定義控制相關的ioctl命令,並且如下支援PIN跟UNPIN的參數,用來讓lowmem_shrinker (Android Low Memory Killer)可以決定是不是在記憶體吃緊時,可以選擇把這塊共享記憶體給強制釋放掉.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int ashmem_pin_region(int fd, size_t offset, size_t len)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct ashmem_pin pin = { offset, len };</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ioctl(fd, ASHMEM_PIN, &pin);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int ashmem_unpin_region(int fd, size_t offset, size_t len)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct ashmem_pin pin = { offset, len };</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ioctl(fd, ASHMEM_UNPIN, &pin);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>B, Binder (Source Code in drivers/staging/android/binder.c)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Binder所扮演的角色,就像是Android中跨行程的IPC(Inter-Process Communication)機制,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以把Binder看做是核心透過裝置/dev/binder提供的一個跨行程的溝通機制,基於Binder作為IPC的溝通媒介,系統中也實作了一個ServiceManager(程式碼位於frameworks/base/cmds/servicemanager/ service_manager.c),用來讓每個Services可以透過Binder向其註冊,與每個Client應用可以透過Binder去查詢目前系統中有哪些註冊的Service可以使用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ServiceManager會在Dalvik也就是整個Android Application運作前,就開啟/dev/binder並呼叫函式binder_become_context_manager透過ioctl帶入參數BINDER_SET_CONTEXT_MGR向核心的Binder註冊自已為Binder機制的管理者,之後,呼叫binder_loop進入一個for (;;) {…}無窮迴圈,接收來自其他Binder Client的要求或是Service的註冊動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考frameworks\base\cmds\servicemanager中的service_manager.c和binder.c原始碼,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<frameworks\base\cmds\servicemanager\Binder.c></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
void binder_loop(struct binder_state *bs, binder_handler func)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int res;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
struct binder_write_read bwr;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
unsigned readbuf[32];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bwr.write_size = 0;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bwr.write_consumed = 0;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bwr.write_buffer = 0;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
readbuf[0] = BC_ENTER_LOOPER;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
binder_write(bs, readbuf, sizeof(unsigned));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
for (;;) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bwr.read_size = sizeof(readbuf);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bwr.read_consumed = 0;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bwr.read_buffer = (unsigned) readbuf;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
res = ioctl(bs->fd, BINDER_WRITE_READ, &bwr);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (res < 0) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGE(“binder_loop: ioctl failed (%s)\n”, strerror(errno));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
res = binder_parse(bs, 0, readbuf, bwr.read_consumed, func);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (res == 0) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGE(“binder_loop: unexpected reply?!\n”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (res < 0) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGE(“binder_loop: io error %d %s\n”, res, strerror(errno));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前看到ServiceManager行程的實作,是透過ioctl等待來自Binder驅動來的其他行程的要求,ServiceManager由於是處在一個for (;;) {…} Busy Loop中,也因此,只要他被系統排程執行到,就會不斷的透過ioctl帶入參數BINDER_WRITE_READ去讀取相關的訊息,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以參考Linux Kernel “drivers/staging/android/binder.c” 原始碼,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…………………..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
ret = wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);//當binder_stop_on_user_error >=2 會讓行程進入睡眠,直到透過wake_up喚醒</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (ret)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ret;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mutex_lock(&binder_lock);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
………………………………</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
err:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (thread)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
thread->looper &= ~BINDER_LOOPER_STATE_NEED_RETURN;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mutex_unlock(&binder_lock);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (ret && ret != -ERESTARTSYS)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printk(KERN_INFO “binder: %d:%d ioctl %x %lx returned %d\n”, proc->pid, current->pid, cmd, arg, ret);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return ret;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果在Binder運作的過程中有呼叫到binder_user_error 巨集,就會導致binder_stop_on_user_error被設定為2,也會讓所有呼叫到Binder ioctl的行程被暫時停止,直到重新Wake up.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從User Mode到Kernel Mode的Code,基本上都是處於一有進入排程,就會不斷的透過ioctl確認是否有來自其他行程的IPC資料,這種處於Busy Loop的Task,跟之前在RTOS手機上,為了考量省電行為,會避免Busy Loop而儘快讓系統掉到Idle Task並確認下一個最短Timer時間點,是在許可值中,就會立刻休眠的想法有所不同.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前Android系統主要是透過Wake Lock的機制,來判斷系統是否進入休眠,所以雖然行程是被排程到後不斷的透過ioctl確認是否有IPC資料,但只要系統的Wake Lock有被釋放,系統省電機制並不會被影響到.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考函式 “svcmgr_handler”,我們可以知道ServiceManager本身主要處理以下四個訊息</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, SVC_MGR_GET_SERVICE : 用來取得目前進行IPC的服務Handle</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, SVC_MGR_CHECK_SERVICE (行為與SVC_MGR_GET_SERVICE一致)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, SVC_MGR_ADD_SERVICE: 用來註冊新增一個新的服務</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4, SVC_MGR_LIST_SERVICES: 列出目前有對ServiceManager註冊的所有服務</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
上層應用程式使用Binder主要透過/system/lib/libbinder.so,對應到的原始碼路徑為”frameworks/base/libs/binder”,應用程式可以透過IServiceManager(in IServiceManager.cpp) 介面開啟 /dev/binder達到跨行程通訊的目的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>C, Logger (Source Code in drivers/staging/android/logger.c)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
不同於Linux本身的Console Log(也可透過dmesg顯示Log Buffer內容或是klogd在遠程觀看),Android提供了LogCat工具讓開發者可以觀察由Android系統所產生的Log訊息.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
目前Android共支援以下五類Log訊息的顯示(順序為嚴重等級),</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1, Verbose: 在LogCat中顏色為黑色,使用的函式為 Log.v</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2, Debug: 在LogCat中顏色為藍色的,使用的函式為 Log.d</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3, Information: 在LogCat中顏色為綠色,使用的函式為 Log.i</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4, Warning: 在LogCat中顏色為橙色,使用的函式為 Log.w</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
5, Error: 在LogCat中顏色為紅色,使用的函式為 Log.e</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
依據上述順序,如果在LogCat選擇 “I”,就只會有Information,Warning與Error等級被顯示出來. 如果點選”E”,則只會看到屬於Error等級的訊息.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在Native程式的開發中,可以在C程式碼中透過LOGV,LOGD,LOGI,LOGW與LOGE讓原生的程式碼可以顯示這五種Log訊息到LogCat中,如下範例程式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <string.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <stdlib.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#define LOG_TAG “C LOG DEMO”</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef LOG</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#undef NDEBUG</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#include <utils/Log.h></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGV(“Hello! This color is for Verbose.”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGD(“Hello! This color is for Debug.”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGI(“Hello! This color is for Information”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGW(“Hello! This color is for Warnning.”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
LOGE(“Hello! This color is for Error.”);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在核心Logger啟動後,會產生以下三個裝置節點</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/dev/log/radio</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/dev/log/events</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/dev/log/main</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
原生的應用程式,可以透過如下的函式直接對Logger作讀寫的動作</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
open(“/dev/log/main”, O_WRONLY) (Source Code 在bionic/linker/linker_format.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>D, Power Management (Source Code in kernel/power)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
手持裝置上電池的容量都是有限的,因此每個移動裝置都會有對應的電源管理機制在,可以根據應用程式的狀態,決定每個硬體裝置是不是可以被關閉,進而透過PMIC (Power Management IC)與Clock Gating的機制,達成系統省電的目的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android自然也有自己一套基於Application Framework與核心Power 相關驅動的管理機制(也可以參考Google的文件<a href="http://www.netmite.com/android/mydroid/development/pdk/docs/power_management.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.netmite.com/android/mydroid/development/pdk/docs/power_management.html</a> 與 <a href="http://developer.android.com/reference/android/os/PowerManager.html" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://developer.android.com/reference/android/os/PowerManager.html</a>).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
簡單來說,如果沒有任何一個應用程式透過 ” Wake Locks”要求處理器不能睡,那處理器就會進入休眠的狀態,一般應用程式可以透過PowerManager要求的Wake Locks大概有以下四類</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px; width: 85%px;"><thead>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top"><strong>Flag Value</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top"><strong>CPU</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top"><strong>Screen</strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top"><strong>Keyboard</strong></td></tr>
</thead><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top"><strong><a href="http://developer.android.com/reference/android/os/PowerManager.html#PARTIAL_WAKE_LOCK" style="color: #666666; text-decoration-line: none;">PARTIAL_WAKE_LOCK</a></strong><strong></strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">On</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">Off</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">Off</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top"><strong><a href="http://developer.android.com/reference/android/os/PowerManager.html#SCREEN_DIM_WAKE_LOCK" style="color: #666666; text-decoration-line: none;">SCREEN_DIM_WAKE_LOCK</a></strong><strong></strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">On</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">Dim</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">Off</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top"><strong><a href="http://developer.android.com/reference/android/os/PowerManager.html#SCREEN_BRIGHT_WAKE_LOCK" style="color: #666666; text-decoration-line: none;">SCREEN_BRIGHT_WAKE_LOCK</a></strong><strong></strong></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">On</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">Bright</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">Off</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top"><strong><a href="http://developer.android.com/reference/android/os/PowerManager.html#FULL_WAKE_LOCK" style="color: #666666; text-decoration-line: none;">FULL_WAKE_LOCK</a></strong><strong></strong></td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">On</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">Bright</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top">Bright</td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
例如,現在有一個MP3 Playback應用程式正在執行,應用程式可以要求”Partial Wake Lock”,讓處理器可以持續的解碼MP3進行音樂的播放,同時又可以關閉螢幕與鍵盤的背光,節省電源.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若是目前處理使用者介面互動的狀態,使用者需要透過鍵盤輸入與觀看螢幕上的內容,就可以透過要求”Full Wake Lock”,讓處理器正常運作,並且同時開啟螢幕與鍵盤的背光.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考” frameworks/base/core/java/android/os/PowerManager.java”原始碼,其實應用程式還有第五個Wake Lock的選擇 “PROXIMITY_SCREEN_OFF_WAKE_LOCK”,不過目前這並不包括在Google SDK的說明文件中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此外,位於核心的驅動還可以透過函式android_register_early_suspend註冊在系統休眠前,根據平台的差異要做的事情,例如:完全關閉Display裝置.或是透過函式android_register_early_resume註冊系統啟動時,在核心驅動要讓系統正常運作前,必須預先準備完成的事情.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
事實上,每個硬體驅動,都還可以在沒有被上層應用程式使用時,透過PMIC關閉電源,或根據SoC的配置透過Clock Gating節省電源的消耗,這些控制的機制,目前並沒有包含在PowerManager機制,應該是我們自己在移植Android環境的人,撰寫周邊驅動與整合時,需要另行實作的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>E, Low Memory Killer(Source Code in drivers/staging/android/lowmemorykiller.c)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux Kernel本身有支援在每次透過Page Allocate配置記憶體時(Source Code在mm/page_alloc.c),透過核心的OOM模組(Source Code 在mm/oom_kill.c),評估目前記憶體資源是不是快耗盡,如果是就會透過函式mem_cgroup_out_of_memory呼叫select_bad_process選擇一個透過badness計算後,要被終止的行程,然後呼叫函式oom_kill_process,最後在函式__oom_kill_task中發送SIGKILL Signal強制終止行程執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以透過 make menuconfig 進入 “General setup”->”Control Group Support”->”Resource counters”->”Memory Resource Controller for Control Groups” 設定編譯參數 “CONFIG_CGROUP_MEM_RES_CTLR=y”,就可以讓Linux kernel 開啟 OOM的功能.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從arch/arm/configs/goldfish_defconfig來看,目前OOM的功能Android上Linux Kernel預設是不開啟的,如此也可避免跟Android本身的Low Memory Killer行為重疊.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android的Low Memory Killer會呼叫函式register_shrinker註冊自己的lowmem_shrinker服務, shrinker的機制是由原本Linux Kernel Memory Management的機制所提供的,主要實作在mm/vmscan.c中,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
mm/vmscan.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/*</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
* Add a shrinker callback to be called from the vm</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
*/</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
void register_shrinker(struct shrinker *shrinker)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
shrinker->nr = 0;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
down_write(&shrinker_rwsem);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
list_add_tail(&shrinker->list, &shrinker_list);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
up_write(&shrinker_rwsem);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
register_shrinker會把lowmem_shrinker註冊到shrinker_list中,而shrinker_list被處理的時間點,則是在當系統記憶體要進行回收時,會呼叫函式shrink_slab,進行檔案系統快取的回收時,就會一併處理到lowmem_shrinker的動作,進行Android系統中的記憶體回收流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Shrinker呼叫函式lowmem_shrink進行記憶體回收的動作,會找出task_struct-> oomkilladj值最大的行程為標的,若有兩個行程的task_struct-> oomkilladj相同,則選擇佔用記憶體最大的行程,透過SIGKILL Signal強制終止行程執行,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每次找尋行程時,會把min_adj 定義為OOM_ADJUST_MAX + 1 (OOM_ADJUST_MAX=15),並取得NR_FREE_PAGES (目前Free狀態的Pages個數) 與 NR_FILE_PAGES (目前在Cache與Buffer中所佔的Pages個數),我目前的理解,在NR_FILE_PAGES中所包含的Cache個數指的是所暫存的檔案內容,而Buffer指的是所暫存的檔案系統inode內容,當我們在檔案系統中搜尋目錄或是讀寫檔案時,就會透過Buffer加速在檔案系統中inode的查找效率,與透過Cache加速所讀寫的檔案內容(實際會根據檔案系統現況,分布在不同的位置).</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int other_free = global_page_state(NR_FREE_PAGES);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int other_file = global_page_state(NR_FILE_PAGES);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
定義閒置記憶體大小與所對應的lowmem_adj數值,目前有四種層級的數值,如果閒置記憶體越多,則選擇回收記憶體要求的task_struct-> oomkilladj越大,也就越少行程有機會被回收.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static int lowmem_adj[6] = {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
1,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
6,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
12,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static int lowmem_adj_size = 4;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static size_t lowmem_minfree[6] = {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
3*512, // 6MB <strong>—-</strong><strong>每個</strong><strong>Page</strong><strong>對應的大小為</strong><strong>4kbytes</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
2*1024, // 8MB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4*1024, // 16MB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
16*1024, // 64MB</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然後根據目前Free與Cache中的Pages個數,去對應預先定義的四個層級,決定lowmem_adj的值.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
for(i = 0; i < array_size; i++) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (other_free < lowmem_minfree[i] &&</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
other_file < lowmem_minfree[i]) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
min_adj = lowmem_adj[i];</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
break;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果目前系統中Free與Cache的Page個數,兩者有一個大於64MB大小的話, min_adj 值會等於OOM_ADJUST_MAX + 1,也就不會進行任何行程記憶體的回收動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (nr_to_scan <= 0 || min_adj == OOM_ADJUST_MAX + 1) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
lowmem_print(5, “lowmem_shrink %d, %x, return %d\n”, nr_to_scan, gfp_mask, rem);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return rem;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從/init.rc中可以看到啟動時 init被設定的oom_adj=-16,這可以確保init行程不會被回收.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# Set init its forked children’s oom_adj.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /proc/1/oom_adj -16</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
上述的lowmem_adj與lowmem_minfree也可以在啟動過程中透過/init.rc設定,如下所示,由於原本定義的Array個數為6個,最多設定的值也以此為限.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,5632,6144</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從這也可以看到Low Memory Killer計算原則的改變<a href="https://www.codeaurora.org/gitweb/quic/la/?p=kernel/common.git;a=commitdiff;h=ff7229900f4d265e9aac633d845e0a7c52b48bf0" style="color: #666666; font-weight: bold; text-decoration-line: none;">https://www.codeaurora.org/gitweb/quic/la/?p=kernel/common.git;a=commitdiff;h=ff7229900f4d265e9aac633d845e0a7c52b48bf0</a>.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>F, PMEM (Source Code in drivers/misc/pmem.c)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PMEM主要的功能是在實體記憶體中配置一塊連續的記憶體,這塊記憶體將不會納入Linux Kernel Memory Management管理的範圍中,這類連續的實體記憶體配置適合用在Display Buffer或是ARM跟DSP需要搬移區塊資料的應用上.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PMEM使用時,可註冊所配置的這塊記憶體是不是要開ARM的Cache,以上述例子而言,如果是屬於硬體會直接讀寫的記憶體區塊,為了要避免在ARM上執行的程式因為Cache中的暫存與被硬體直接修改的記憶體內容不一致所導致的錯誤,屬於這類的記憶體就會關閉ARM的Cache.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
實際的開發中,如果有針對同一個被設定為開Cache的PMEM裝置,希望有不同的應用,可以關閉Cache,可以在開啟該裝置時加上O_SYNC參數,例如</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fd = open(“/dev/pmem”, O_RDWR | O_NONBLOCK | O_SYNC);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
….</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考drivers/misc/pmem.c,在開啟 PMEM裝置後,進行MMAP</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static int pmem_mmap(struct file *file, struct vm_area_struct *vma)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_page_prot);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static pgprot_t phys_mem_access_prot(struct file *file, pgprot_t vma_prot)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int id = get_id(file);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef pgprot_noncached</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (pmem[id].cached == 0 || file->f_flags & O_SYNC)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return pgprot_noncached(vma_prot);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#ifdef pgprot_ext_buffered</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else if (pmem[id].buffered)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return pgprot_ext_buffered(vma_prot);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#endif</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return vma_prot;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在開啟PMEM裝置時,如果有設定O_SYNC,在MMAP時就會透過pgprot_noncached回傳關閉Cache的狀態.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果該區塊記憶體只有ARM上的程式會讀寫,開啟Cache就可以減少每次都要去外部記憶體讀寫的延遲,又可以達到加速的目的,不過,如果該區塊記憶體只有ARM會讀寫,其實也沒有必要獨立於Linux Kernel Memory Management外配置一塊連續的實體記憶體,若有Shared Memory需求就透過Ashmem,或是由行程直接配置就好,不必使用時就可以釋出,以便基於Memory Management機制,提高記憶體的使用率.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
PMEM可以透過make menuconfig的選項, Device Drivers ->Misc devices –> Android pmem allocator決定是否開啟,並且要加入相關的Source Code才讓PMEM產生作用.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以網路上目前可以抓到的HTC 在Qualcomm平台上的配置來說 (Source Code in http://neophyte.vipme.com/gpl/bravo-2.6.32.24/arch/arm/mach-msm/devices_htc.c)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
定義兩個Android PMEM的裝置,分別為 /dev/pmem與/dev/pmem_adsp,,pmem開啟Cache,而pmem_adsp關閉Cache.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static struct android_pmem_platform_data pmem_pdata = {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.name = “pmem”,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.no_allocator = 1,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.cached = 1,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static struct android_pmem_platform_data pmem_adsp_pdata = {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.name = “pmem_adsp”,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.no_allocator = 0,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.cached = 0,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static struct platform_device pmem_device = {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.name = “android_pmem”,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.id = 0,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.dev = { .platform_data = &pmem_pdata },</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
static struct platform_device pmem_adsp_device = {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.name = “android_pmem”,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.id = 1,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.dev = { .platform_data = &pmem_adsp_pdata },</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
};</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過platform_device_register註冊上述兩個PMEM裝置</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
void __init msm_add_mem_devices(struct msm_pmem_setting *setting)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (setting->pmem_size) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pmem_pdata.start = setting->pmem_start; <strong>//</strong><strong>設定對應到實體記憶體的位置</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pmem_pdata.size = setting->pmem_size; <strong>//</strong><strong>設定對應到實體記憶體的大小</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
platform_device_register(&pmem_device);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (setting->pmem_adsp_size) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pmem_adsp_pdata.start = setting->pmem_adsp_start; <strong>//</strong><strong>設定對應到實體記憶體的位置</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
pmem_adsp_pdata.size = setting->pmem_adsp_size; <strong>//</strong><strong>設定對應到實體記憶體的大小</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
platform_device_register(&pmem_adsp_device);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
………</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據我們把實體記憶體最後的區塊設定給PMEM使用的大小,也要同步修改傳入核心的bootargs,把MEM值對應修改,調整實體記憶體納入Linux Kernel Memory Management的大小.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>其他的改變還包括,</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>1,支援RAM Console(Source Code in drivers/staging/android/ram_console.c)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以透過make menuconfig 選單,”Device Drivers”->”Staging Drivers”->”Android”->”Android RAM buffer console”設定是否開啟RAM Control,以及設定記憶體位置與大小,讓開發核心相關的模組時,可以依據需求決定相關參數. 其實Linux Kernel本身就有維持一個Log Ring-Buffer的機制,根據arch/arm/configs/goldfish_defconfig中的設定CONFIG_LOG_BUF_SHIFT=16,在編譯時會指定 kernel/printk.c中的變數 log_buf_len (__LOG_BUF_LEN) = 64kbytes (1 << CONFIG_LOG_BUF_SHIFT),也就是我們透過dmesg可以在本機看到的訊息來源,我目前的理解,這兩者功能上是有重疊的. 也可能是因為如此,所以RAM Console在goldfish_defconfig 中設預是不開啟的,只用於開發階段需要比較大的Log紀錄輔助除錯時.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
//來自 <cite>IRead => </cite>ram console 主要的功能是在系統掛掉後,reboot時能保留前次開機最後的 kernel log</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2,Alarm (Source Code in drivers/rtc/alarm.c)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在系統休眠時,只有RTC石英振盪器還維持運作,基於PLL振盪器的Timer,都會沒有作用,在Feature Phone上,會把下次Modem或是人機介面要醒來的時間,透過RTC喚醒.同樣的在Android這樣的平台上,雖然沒有關於Modem醒來時間需要處理,但有關鬧鐘,事件提醒或是到特定時間需要軟體處理的工作,在系統休眠時,除非正好使用者透過按鍵把手機喚醒回到正常執行的狀態,不然就只有透過RTC這類外部的中斷,讓處理器可以到指定的時間被喚醒,執行預定的工作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android也基於RTC提供了Alarm的驅動,並在/dev/alarm中註冊裝置,上層應用程式可以透過AlarmManagerService或是libutils中System Clcok的函式setCurrentTimeMillis/elapsedRealtime,開起該裝置檔案,透過ioctl設定/讀取相關RTC的時間參數與動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3,Timed Device (Source Code in drivers/staging/android/timed_gpio.c and drivers/staging/android/timed_output.c)</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
主要用於手機上需要有時間周期控制的GPIO裝置,例如Service LED的周期明亮,或是一次性的時間Timer動作,例如鍵盤LED背光,或是震動.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
註冊Timed GPIO的動作可以透過函式timed_gpio_probe,從timed_gpio_platform_data中可以取得目前要動作的GPIO個數,之後再透過timed_gpio結構取得每個GPIO所對應的位置,周期結束時間,以及該GPIO輸出的高或低電位. 當該GPIO TimeOut的時間到時,就會呼叫gpio_timer_func,並在該函式中呼叫gpio_direction_output對該GPIO進行輸出電位的調整. 每一次TimeOut後,如果要讓該GPIO可以週期性的作用,就要重新呼叫函式gpio_enable,以便成為一個週期性的GPIO動作.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>2, </strong><strong>支援</strong><strong>CPIO Ramdisk</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
利用Linux Kernel 2.6之後導入的TmpFS,以CPIO的Ramdisk格式取代過去透過Memory Block Device搭配Ext2的做法(至少,我是這樣子做滴…),如下所示為之前產生Ramdisk與手動載入Ramdisk的範例</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# dd if=/dev/zero of=/temp/initrd bs=1024 count=4096 (產生4MB的檔案)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4096+0 records in</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4096+0 records out</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4194304 bytes (4.2 MB) copied, 0.188288 seconds, 22.3 MB/s</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# losetup /dev/loop0 /temp/initrd (對應 /temp/initrd到loop裝置)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# mkfs.ext2 /dev/loop0 (格式化 /temp/initrd 為ext2 檔案系統)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# mount /dev/loop0 /mnt/ (把產生的4MB /temp/initrd 載入到目錄 /mnt)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# vi /mnt/hello (在/mnt中產生一個範例檔案hello)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# umount /mnt (卸載目錄 /mnt)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# losetup -d /dev/loop0 (移除 loop0裝置)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# gzip -9 /temp/initrd (gzip壓縮Ramdisk檔案)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# ls /temp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
initrd.gz</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# gzip -dc /temp/initrd.gz > initrd (解壓縮 Ramdisk)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# mkdir test (產生測試目錄)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# mount -o loop ./initrd test (以loop裝置把Ramdisk 載入到test目錄)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# ls test</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
hello lost+found</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]#</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以發現原本的做法,需要預估一個Ramdisk可能需要的空間,如果沒有預估好,可能就會導致有一些記憶體空間浪費,而且在整個操作流程中,也相形比較複雜.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下為透過CPIO的機制,來取代過去Ramdisk的做法.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda generic]# cd root</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda root]# du</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8 ./sys</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8 ./proc</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
152 ./sbin</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8 ./system</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8 ./dev</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
8 ./data</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
352 .</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda root]# find ./ | cpio -H newc -o > ../root.img</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
512 blocks</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda root]# ls -l ../root.img</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rw-r–r– 1 root root 262144 Jan 18 20:14 ../root.img</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda root]# cd ..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda generic]# gzip -9 root.img</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda generic]# ls -l root.img.gz</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rw-r–r– 1 root root 165918 Jan 18 20:17 root.img.gz</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以作為開機檔案系統的根而言,兩者都會透過gz壓縮節省儲存的空間,不過早期Ramdisk的做法,在記憶體空間使用上,與載入的動作,流程上比較多,但優點是可以寫入暫存資料,當作一個效率很高的可讀/寫檔案系統. CPIO Ramdisk格式可以直接由TmpFS載入,唯讀,儲存空間直接對應到實際資料的空間,可以避免記憶體浪費的問題. 並且,不需要經過Memory Block Device額外一層的動作,直接對應到記憶體中,對於初始化的效率與空間使用上都有比較好的效果.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>3, </strong><strong>支援新的</strong><strong>Prelink</strong><strong>機制</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Linux環境中的Prelink是由在RedHat的Jakub Jelinek所開發的(Wiki <a href="http://en.wikipedia.org/wiki/Prelink" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://en.wikipedia.org/wiki/Prelink</a>),基於這個機制,應用程式啟動時,所使用到的動態函式庫會根據預先規劃好的記憶體位置透過ld.so擺放,也因為是預先規劃好的擺放位置,在記憶體的使用上也可以比較節省.而有經過Prelink處理的執行檔,也會根據預先規劃好的動態函式庫記憶體位置,直接修改ELF執行檔Symbol對應的位址,加速載入後,每個呼叫外部函式庫Symbol重定位的成本.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果要針對所在環境進行Prelink,可以執行</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
prelink –avmR</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要取消Prelink可以執行</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
prelink –au</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以如下的C Code 說明Linux上Prelink的作用,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char *vTmp;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vTmp=(char *)malloc(32);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vTmp==0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memset(vTmp,0x00,32);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
strcpy(vTmp,”123″);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memcpy(&vTmp[3],”456″,3);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“%s\n”,vTmp);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
free(vTmp);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
以筆者電腦為例,編譯完成後,我們透過objdump可以看到_GLOBAL_OFFSET_TABLE_中 free的位址是指向0x080482da,malloc的位址是指向0x080482ea,puts的位址是指向0x080482fa.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
對編譯出來的執行檔下 prelink –vm 指令後,再透過objdump查看_GLOBAL_OFFSET_TABLE_, free的位址是指向0x0018d990,malloc的位址是指向0x0018fe30,puts的位址是指向0x0017de80.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
要驗證prelink是不是真的把用到libc的函式指到正確的記憶體位置,而不是在程式運作時才動態的進行Relocate,我們再透過objdump反組譯/lib/libc-2.5.so,找到上面三個位址所對應到的程式碼,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0018d990 <__libc_free>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18d990: 55 push %ebp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18d991: 89 e5 mov %esp,%ebp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18d993: 83 ec 30 sub $0x30,%esp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18d996: 89 5d f4 mov %ebx,0xfffffff4(%ebp)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18d999: 8b 55 08 mov 0x8(%ebp),%edx</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18d99c: e8 3f c3 fa ff call 139ce0 <__i686.get_pc_thunk.bx></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18d9a1: 81 c3 53 86 0d 00 add $0xd8653,%ebx</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…….</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0018fe30 <__libc_malloc>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18fe30: 55 push %ebp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18fe31: 89 e5 mov %esp,%ebp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18fe33: 83 ec 18 sub $0x18,%esp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18fe36: 89 5d f4 mov %ebx,0xfffffff4(%ebp)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18fe39: e8 a2 9e fa ff call 139ce0 <__i686.get_pc_thunk.bx></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
18fe3e: 81 c3 b6 61 0d 00 add $0xd61b6,%ebx</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0017de80 <_IO_puts>:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17de80: 55 push %ebp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17de81: 89 e5 mov %esp,%ebp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17de83: 83 ec 1c sub $0x1c,%esp</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17de86: 89 5d f4 mov %ebx,0xfffffff4(%ebp)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17de89: 8b 45 08 mov 0x8(%ebp),%eax</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17de8c: e8 4f be fb ff call 139ce0 <__i686.get_pc_thunk.bx></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
17de91: 81 c3 63 81 0e 00 add $0xe8163,%ebx</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
……</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然後,讓程式實際的跑起來查看/proc/7345/maps (7345是我程式執行的PID)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00101000-0011b000 r-xp 00000000 fd:00 12190991 /lib/ld-2.5.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0011b000-0011c000 r-xp 00019000 fd:00 12190991 /lib/ld-2.5.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0011c000-0011d000 rwxp 0001a000 fd:00 12190991 /lib/ld-2.5.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00124000-00263000 r-xp 00000000 fd:00 12191004 /lib/libc-2.5.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00263000-00264000 –xp 0013f000 fd:00 12191004 /lib/libc-2.5.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00264000-00266000 r-xp 0013f000 fd:00 12191004 /lib/libc-2.5.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00266000-00267000 rwxp 00141000 fd:00 12191004 /lib/libc-2.5.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00267000-0026a000 rwxp 00267000 00:00 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以知道/lib/libc-2.5.so有正確的被載入到上述記憶體空間中,而執行檔經過Prelink重定位的記憶體位置也跟/lib/libc-2.5.so實際被載入到的記憶體位置一致,驗證Prelink確實把執行檔ELF中的_GLOBAL_OFFSET_TABLE_修正正確,達到程式載入加速的目的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果在程式載入時,發現有建立Prelink資訊的動態函式庫在記憶體的相關位置改變了,ld.so就會進行原本的動態函式庫Symbol重定位的流程,確保應用程式還是可以正常的執行.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Prelink所依據的資訊,主要來自於/etc/prelink.conf中所記載的應用程式路徑與動態函式庫路徑,他會去統計這些路徑中所有的執行檔與動態函式庫,幫每個動態函式庫配置一個記憶體位置,然後再根據上述動態函式庫所備配置的記憶體位置,去修改每個執行檔中所參考到相關動態函式庫函式的記憶體位置,每個動態函式庫所配置的記憶體位置,也會紀錄到ELF檔案中,以便在下次執行時,可以透過Prelink時對應動態函式庫所配置的記憶體位置查核在實際執行時是不是有正確對應,以便判斷是不是要進行動態的函式庫Symbol重定位的流程.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
說完了Linux原本支援的Prelink機制,接下來我們再來看Android 的Prelink機制Apriori. (Source Code in build/tools/apriori) ,Google一下Apriori的命名意義,在演算法中Apriori是一種關聯演算法,主要用於Data Mining,例如可用來分析使用者購物的行為關係,找出有意義的資訊. 這跟Prelink必須要先蒐集動態函式庫的資訊後,再來幫助ELF執行檔預先解決記憶體中Symbol關聯的問題,有類似的含意.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Apriori這工具所參考的動態函式庫記憶體位址是透過預先定義好的Maps檔案支援的,參考Android編譯環境中的build/core/definitions.mk我們可以知道Apriori所參考的Maps檔案位置在build/core/prelink-linux-arm.map.在這檔案中就記載了每個動態函式庫在執行檔載入時,所預先規劃好對應的記憶體位址,如下所示</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# core system libraries</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libdl.so 0xAFF00000 # [<64K]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libc.so 0xAFD00000 # [~2M]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libstdc++.so 0xAFC00000 # [<64K]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libm.so 0xAFB00000 # [~1M]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
liblog.so 0xAFA00000 # [<64K]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libcutils.so 0xAF900000 # [~1M]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libthread_db.so 0xAF800000 # [<64K]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libz.so 0xAF700000 # [~1M]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libevent.so 0xAF600000 # [???]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libssl.so 0xAF400000 # [~2M]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libcrypto.so 0xAF000000 # [~4M]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
libsysutils.so 0xAEF00000 # [~1M]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
接下來我們還是以這段C Code進行編譯,驗證Apriori的作用</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char *vTmp;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vTmp=(char *)malloc(32);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vTmp==0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memset(vTmp,0x00,32);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
strcpy(vTmp,”123″);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memcpy(&vTmp[3],”456″,3);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“%s\n”,vTmp);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
free(vTmp);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
透過Android.mk以BUILD_EXECUTABLE方式編譯出執行檔,之後把執行檔放到Android環境中執行,查核Memory Map中的內容如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# cat /proc/306/maps</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cat /proc/306/maps</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00008000-00009000 r-xp 00000000 1f:00 381 /system/bin/Hello</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00009000-0000a000 rwxp 00000000 1f:00 381 /system/bin/Hello</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0000a000-0000b000 rwxp 0000a000 00:00 0 [heap]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40000000-40008000 r-xs 00000000 00:07 189 /dev/ashmem/system_properties (</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
deleted)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40008000-40009000 r-xp 40008000 00:00 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd00000-afd3f000 r-xp 00000000 1f:00 546 /system/lib/libc.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd3f000-afd42000 rwxp 0003f000 1f:00 546 /system/lib/libc.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
afd42000-afd4d000 rwxp afd42000 00:00 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b0001000-b000c000 r-xp 00001000 1f:00 413 /system/bin/linker</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b000c000-b000d000 rwxp 0000c000 1f:00 413 /system/bin/linker</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
b000d000-b0016000 rwxp b000d000 00:00 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
bed27000-bed3c000 rwxp befeb000 00:00 0 [stack]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
#</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
跟prelink-linux-arm.map中libc對應的記憶體位址相比,我們可以看到/system/bin/linker有正確的參考Apriori根據prelink-linux-arm.map在函式庫 lib*.so ELF 檔案中記錄的記憶體位址,把這些動態函式庫對應到指定的記憶體位置中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
觀察Android的編譯流程,在動態函式庫編譯的過程中,會執行如下的指令/android/froyo/out/host/linux-x86/bin/apriori –prelinkmap /android/froyo/build/core/prelink-linux-arm.map –locals-only –quiet libxxx.so –output libxxx_a.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
根據prelink-linux-arm.map修改lib*.so檔案,並複製到最後產生的system image中.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
此外,Android上Native執行檔(非動態函式庫)的編譯過程中,並沒有像Linux原本的Prelink機制,會去修改ELF執行檔的_GLOBAL_OFFSET_TABLE_,讓執行檔的Symbol跟動態函式庫可以預作定位,Apriori只有針對動態函式庫的部分,參考prelink-linux-arm.map把動態函式庫放到對應的位置上,分析編譯出來的LINKED ELF執行檔,也可確認編譯流程中並沒有針對執行檔參考到的Symbol預作定位.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
從分析的結果來看,其實原本Linux的Prelink作的還是比較完善,包含有亂數定址分配,動態根據函式庫的大小調配優化後的記憶體排列節省空間, prelink-linux-arm.map 本身是透過人為手動設定的,為了確保不要有重疊,相鄰的兩個函式庫就算Size只有幾百kbytes,還是會配置Mbytes以上的記憶體間隔,當然,因為系統上有MMU,並不會造成這些記憶體間隔的浪費,只是,類似Linux Prelink動態根據所有函式庫的大小,來排列優化結果,對Embedded System還是位比較有效益的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>4, </strong><strong>支援新的動態連結核心</strong><strong></strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
每當使用者選擇一個檔案執行時,Linux Kernel會分析檔案的格式,並決定要透過load_aout_binary,load_elf_binary 與load_misc_binary進行後續載入的流程,我們在Android系統上所編譯的Native執行檔的檔案格式就是ELF,當我們透過gcc編譯ELF執行檔時,可以透過 ”-dynamic-linker” 連結選項,設定所產生的ELF執行檔的動態函式庫連結機制,是不是有自己客製的實作,如果我們沒有設定這個參數,預設執行檔的動態函式庫連結機制會採用 ld-linux.so,並透過這個動態函式庫連結機制,載入其他執行檔所需的動態函式庫.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android支援了自己的Apriori Prelink機制,讓應用程式與動態函式庫的載入過程可以得到加速,並且也實作了自己的動態函式庫連結核心linker (在System的路徑為 /system/bin/linker, Source Code in bionic/linker),以便在程式執行時,可以由linker判斷該動態函式庫是不是被Apriori處理過的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
在系統啟動的過程中,由於Android的Linker是被放在CPIO的TmpFS中,因此在root下的/init,會在 system.img載入前就被執行,比Linker能作用的環境更早,因此我們可以看到 /init本身為static link的執行檔.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda root]# file init</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
init: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
由於linker機制的改變,原本在 glibc環境中ld-linux.so支援的Lazy Binding,或像是ld.so.cache動態函式庫搜尋快取也因為有Prelink機制的存在,也沒有存在的必要.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們也可以試著進行如下的編譯,透過指定dynamic linker,產生出一個可在Android環境中執行的ELF檔案 (還請包到 system.img中進行測試)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
arm-eabi-gcc -g -o Hello Hello.c -Wl,-rpath-link=/android/froyo/out/target/product/generic/obj/lib,-dynamic-linker=/system/bin/linker -I/android/froyo/ndk/build/platforms/android-8/arch-arm/usr/include -L/android/froyo/out/target/product/generic/obj/lib -nostdlib /android/froyo/out/target/product/generic/obj/lib/crtbegin_dynamic.o –lc -fno-short-enums</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
基於上述的說明,我們可以知道新的動態函式庫linker的支援,其實是透過ELF編譯時指定的,我們也可以把原本的libc.so與ld-linux.so複製到Android執行環境中,就可以透過Linux Kernel load_elf_binary原本的機制,讓ld-linux.so可以執行跟Android linker一樣的動態函式庫連結工作,並在Android系統中順利的運作.(只是這樣的話就不能使用到 Apriori Prelink的優點了.)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
我們可以從Code Sourcery下載編譯好的Toolchain 網址是<a href="http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2</a> (網站<a href="http://www.codesourcery.com/sgpp/lite/arm/portal/release1600" style="color: #666666; font-weight: bold; text-decoration-line: none;">http://www.codesourcery.com/sgpp/lite/arm/portal/release1600</a>) 下載ARM eabi gcc Cross Compiler環境,解開後,用以下程式碼進行編譯</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int main()</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char *vTmp;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
vTmp=(char *)malloc(32);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if(vTmp==0)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 0;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memset(vTmp,0x00,32);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
strcpy(vTmp,”123″);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
memcpy(&vTmp[3],”456″,3);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
printf(“%s\n”,vTmp);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
free(vTmp);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
return 1;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# arm-none-linux-gnueabi-gcc -g -o hello hello.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
若各位用的Cross Compiler跟筆者不同,建議可以加上 “-Wl,-dynamic-linker</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
=/lib/ld-linux.so.3” 指定動態函式庫linker到/lib/ld-linux.so.3. (或所使用glibc對應的ld-linux檔案名稱)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
驗證檔案格式</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# file hello</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
然後用</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# readelf -d pig6|more</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dynamic section at offset 0x6f4 contains 25 entries:</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Tag Type Name/Value</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
0x00000001 (NEEDED) Shared library: [libc.so.6]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
得知除了ld-linux.so.3外,還需要有libgcc_s.so.1與libc.so.6,因此我們把這三個檔案複製到最後運作時,位於root檔案系統 /lib 的目錄下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda glibc]# cd /android/froyo/out/target/product/generic/root/lib</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda glibc]# cp /home/loda/arm-2010.09/arm-none-linux-gnueabi/libc/lib/ld-linux.so.3 ./</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda glibc]# cp /home/loda/arm-2010.09/arm-none-linux-gnueabi/libc/lib/libc.so.6 ./</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda glibc]# cp /home/loda/arm-2010.09/arm-none-linux-gnueabi/libc/lib/libgcc_s.so.1 ./</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
複製完成後,重新產生 root 與 system檔案系統</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda generic]# cd /android/froyo/out/target/product/generic/root</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda root]# find ./ | cpio -H newc -o > ../ramdisk.img</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4775 blocks</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda root]# cd ..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda generic]# gzip -9 ramdisk.img</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda generic]# mkyaffs2image system/ system.img</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
啟動Android系統後,就可以發現基於 glibc環境的執行檔可以正確運作了,不過由於這個執行檔不是基於Apriori與Android Linker的環境,我們查核/proc下對應程序的Memory Map,結果如下</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
# cat /proc/73/maps</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
cat /proc/73/maps</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00008000-00009000 r-xp 00000000 1f:00 463 /system/bin/pig8</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00010000-00011000 rwxp 00000000 1f:00 463 /system/bin/pig8</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
00011000-00032000 rwxp 00011000 00:00 0 [heap]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40000000-4001f000 r-xp 00000000 00:01 21 /lib/ld-linux.so.3</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4001f000-40022000 rwxp 4001f000 00:00 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40026000-40027000 r-xp 0001e000 00:01 21 /lib/ld-linux.so.3</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40027000-40028000 rwxp 0001f000 00:01 21 /lib/ld-linux.so.3</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40028000-40033000 r-xp 00000000 00:01 24 /lib/libgcc_s.so.1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40033000-4003a000 —p 0000b000 00:01 24 /lib/libgcc_s.so.1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4003a000-4003b000 rwxp 0000a000 00:01 24 /lib/libgcc_s.so.1</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4003b000-40174000 r-xp 00000000 00:01 22 /lib/libc.so.6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
40174000-4017c000 —p 00139000 00:01 22 /lib/libc.so.6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4017c000-4017e000 r-xp 00139000 00:01 22 /lib/libc.so.6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4017e000-4017f000 rwxp 0013b000 00:01 22 /lib/libc.so.6</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
4017f000-40182000 rwxp 4017f000 00:00 0</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
be908000-be91d000 rw-p befeb000 00:00 0 [stack]</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
可以得知,對應函式庫的記憶體位置,跟prelink-linux-arm.map相比,是由/lib/ld-linux.so.3動態決定的.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>5,支援 Toolbox</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
一般的Embedded Linux 通常會考慮用Busybox來減少要支援Linux眾多的指令集檔案,Android本身也有類似Busybox的機制,但實作的方式是另外自己開發Toolbox,原始碼所在目錄為system/core/toolbox,目前共支援以下指令</div>
<table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; color: black; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin: 10px 0px;"><tbody>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">mv</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">df</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">mkdir</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">log</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">dmesg</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">id</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">chmod</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">ioctl</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">cat</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">newfs_msdos</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">renice</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">mount</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">printenv</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">smd</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">lsmod</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">iftop</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">setprop</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">notify</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">watchprops</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">rmmod</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">hd</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">insmod</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">netstat</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">cmp</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">dd</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">kill</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">ionice</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">date</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">start</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">stop</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">sleep</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">getprop</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">sendevent</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">vmstat</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">ln</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">getevent</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">wipe</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">sync</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">schedtop</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">top</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">ifconfig</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">reboot</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">setconsole</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">route</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">rm</td></tr>
<tr><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">nandread</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">ls</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">chown</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120">rmdir</td><td style="border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96">ps</td></tr>
<tr class="alt"><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108">umount</td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="108"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="120"></td><td style="background: rgb(244, 244, 244); border-bottom: 1px solid rgb(221, 221, 221); padding: 4px 8px;" valign="top" width="96"></td></tr>
</tbody></table>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>6, soslim ELF檔案Symbol Strip工具</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android 系統中沒有使用prebuilt目錄下所帶的arm-eabi-strip,而是使用soslim(Source Code in build/tools/soslim)用來刪除ELF執行檔中所帶Symbol資訊,減少執行檔所佔的儲存空間.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如下所示,我用原本的arm-eabi-strip 針對一個10146 bytes的檔案進行strip,最後的檔案大小為5468bytes.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda froyo]# ls -l NonStripFile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x 1 root root 10146 Jan 20 11:50 NonStripFile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda froyo]# arm-eabi-strip NonStripFile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda froyo]# ls -l NonStripFile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x 1 root root 5468 Jan 20 11:51 NonStripFile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
同樣的,我透過soslim對同一個檔案進行strip,最後的檔案大小也為5468bytes.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda froyo]# ls -l NonStripFile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x 1 root root 10146 Jan 20 11:51 NonStripFile</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda froyo]# /android/froyo/out/host/linux-x86/bin/soslim –strip –shady</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
–quiet NonStripFile –outfile NonStripFile_soslim</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda froyo]# ls -l NonStripFile_soslim</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
-rwxr-xr-x 1 root root 5468 Jan 20 11:53 NonStripFile_soslim</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
兩者都有透過刪除Symbol減少檔案大小的功能,主要差異在於soslim有支援Prelink機制的Tags.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
參考build/tools/soslim/prelink_info.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
typedef struct {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
uint32_t mmap_addr;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
char tag[4]; /* ‘P’, ‘R’, ‘E’, ‘ ‘ */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
} prelink_info_t __attribute__((packed));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Apriori的Prelink機制,會把動態函式庫.so檔要對應到記憶體的位址與Tag共8 bytes,儲存到so ELF檔的最後面,如下所示如果是用原本的arm-eabi-strip處理的話,會連帶把Prelink Tag給刪除.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# grep “PRE” libbinder.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Binary file libbinder.so matches</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# arm-eabi-strip libbinder.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]# grep “PRE” libbinder.so</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
[root@loda ~]#</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
如果是透過soslim,參考build/tools/soslim/prelink_info.c</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
void setup_prelink_info(const char *fname, int elf_little, long base)</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
{</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
….</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int fd = open(fname, O_WRONLY);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
FAILIF(fd < 0,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
“open(%s, O_WRONLY): %s (%d)\n” ,</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
fname, strerror(errno), errno);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
prelink_info_t info;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
off_t sz = lseek(fd, 0, SEEK_END);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
….</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
if (!(elf_little ^ is_host_little())) {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* Same endianness */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
INFO(“Host and ELF file [%s] have same endianness.\n”, fname);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
info.mmap_addr = base;</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
else {</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
/* Different endianness */</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
INFO(“Host and ELF file [%s] have different endianness.\n”, fname);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
info.mmap_addr = switch_endianness(base);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
strncpy(info.tag, “PRE “, 4);</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
int num_written = write(fd, &info, sizeof(info));</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
…..</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
}</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
會在把不必要的Symbol刪除後,再把Apriori Prelink 資訊寫回動態函式庫 so ELF檔案的最後面.</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>7, acp Android提供的CP檔案複製工具.</strong></div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Android 也提供自己的檔案複製工具acp, 在此僅附上Source Code build/tools/acp 前面的說明,供參考</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
The GNU/Linux “cp” uses O_LARGEFILE in its open() calls, utimes() instead of utime(), and getxattr()/setxattr() instead of chmod(). These are probably “better”, but are non-portable, and not necessary for our</div>
<div style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
purposes.</div>
</div>
Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-9825629365644943462017-06-01T09:44:00.004-07:002017-06-01T09:44:47.950-07:00Windows .Net 與 CLR技術剖析<a href="https://www.blogger.com/goog_966129816"><br /></a>
<a href="https://www.blogger.com/goog_966129816"><br /></a>
<span style="color: #666666; font-family: tahoma, arial, sans-serif;"><span style="background-color: white; font-size: 12.8px;"><b><a href="https://www.blogger.com/goog_966129816">Windows .Net 與 CLR技術剖析</a></b></span></span><br />
<a href="https://drive.google.com/open?id=0B5pbq4t2T2_feUNISmo3b2t6Sjg">https://drive.google.com/open?id=0B5pbq4t2T2_feUNISmo3b2t6Sjg</a>Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-54315431401511145752017-06-01T09:44:00.000-07:002017-06-01T09:44:01.438-07:00802.16e Security 技術介紹<a href="https://www.blogger.com/goog_966129810"><br /></a>
<a href="https://www.blogger.com/goog_966129810"><br /></a>
<strong style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px;"><a href="https://www.blogger.com/goog_966129810"><span style="color: #666666;">802.16e Security 技術介紹</span><br />(based on the IEEE 802.16e/D4 August 2004)</a></strong><br />
<span style="background-color: white; font-size: 12.8px;"><span style="font-family: tahoma, arial, sans-serif;"><b><a href="https://drive.google.com/open?id=0B5pbq4t2T2_fc0tyeUstVjNibkk">https://drive.google.com/open?id=0B5pbq4t2T2_fc0tyeUstVjNibkk</a></b></span></span>Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-8760353034148673602017-06-01T09:42:00.003-07:002017-06-01T09:42:36.006-07:00802.16d Security 技術介紹<a href="https://www.blogger.com/goog_966129805"><br /></a>
<a href="https://www.blogger.com/goog_966129805"><br /></a>
<strong style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px;"><a href="https://www.blogger.com/goog_966129805"><span style="color: #666666;">802.16d Security 技術介紹</span><br />(based on the IEEE P802.16-REVd/D5 May 2004)</a></strong><br />
<span style="background-color: white; font-size: 12.8px;"><span style="font-family: tahoma, arial, sans-serif;"><b><a href="https://drive.google.com/open?id=0B5pbq4t2T2_fa2tfUXlScWRsVlk">https://drive.google.com/open?id=0B5pbq4t2T2_fa2tfUXlScWRsVlk</a></b></span></span>Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-86972519971857256112017-06-01T09:41:00.003-07:002017-06-01T09:41:25.877-07:00介紹作業系統概念的投影片<a href="https://www.blogger.com/goog_966129800"><br /></a>
<a href="https://www.blogger.com/goog_966129800"><br /></a>
<strong style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px;"><span style="color: #666666;"><a href="https://www.blogger.com/goog_966129800">介紹作業系統概念的投影片</a></span></strong><br />
<a href="https://drive.google.com/open?id=0B5pbq4t2T2_fR29MSkpxZ2NJUEk">https://drive.google.com/open?id=0B5pbq4t2T2_fR29MSkpxZ2NJUEk</a>Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0tag:blogger.com,1999:blog-1668810802505961314.post-22831720000731232542017-06-01T09:39:00.003-07:002017-06-01T09:39:32.985-07:00Embedded Linux Windows Solution<a href="https://www.blogger.com/goog_966129794"><br /></a>
<a href="https://www.blogger.com/goog_966129794"><br /></a>
<strong style="background-color: white; font-family: tahoma, arial, sans-serif; font-size: 12.8px;"><span style="color: #666666;"><a href="https://www.blogger.com/goog_966129794">Embedded Linux Windows Solution</a></span></strong><br />
<a href="https://drive.google.com/open?id=0B5pbq4t2T2_faERiSmpsbWllRzg">https://drive.google.com/open?id=0B5pbq4t2T2_faERiSmpsbWllRzg</a>Lawpighttp://www.blogger.com/profile/03242765372558282851noreply@blogger.com0