foxhoundsk
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 2019q1 Homework4 (smallsys) contributed by < `flawless0714` > ## 自我檢查清單 * 你是否詳閱 [手機裡頭的 ARM 處理器:系列講座](http://hackfoldr.org/arm/) 呢?請紀錄學習過程中遇到的問題 * 請解釋 AArch64 個別通用暫存器的作用,依據 [Linux on AArch64 ARM 64-bit Architecture](https://events.static.linuxfound.org/images/stories/pdf/lcna_co2012_marinas.pdf) 的描述,搭配實際的程式碼說明。提示: 簡報第 19 頁附有參考資訊 - **回答** - 暫存器 - 共有31個大小為 64-bit 的通用暫存器(X0~X30); - X0 ~ X7 為 parameter/result 暫存器; - X8 (XR) 為 indirect result location 暫存器 主要用於保存函數回傳大物件(e.g. 大結構體)時大物件的記憶體位置,以減少暫存器的使用量(一般函數回傳值僅用暫存器來保存)。 - X9 ~ X15 為 temporary 暫存器 通常用於保存區域變數。 - X16 ~ X17 (跟別為 IP0, IP1) 用於 intra-procedure-call (保存 Veneer code ([詳見](https://hackmd.io/ES9ZOdizTxKkmtCMkeCMKw?view#Veneer-code))與 [PLT code](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0242a/BCGHGBDH.html) 之位置),也可當作 temporary 暫存器用。 - X18 可作為 platform 暫存器用,也可作為 temp 暫存器。 - X19 ~ X28 Callee saved register。這幾個暫存器在 function call 或 context switch 時應由 callee 保存。 - X29 (FP, Frame Pointer); - X30 (LR, Link Register) 注意,在 AArch64 下切換 exception level 時不會用到此暫存器(僅用於一般 function call 等等),而是使用 ELR 暫存器。 - 不同的 Exception Level 有個別的 SP (Stack Pointer); - ELR 暫存器 AArch64 處理器有四個 privilege level (EL0~EL3)。而切換這些 privilege level 則是透過 exception 進行,每當發生切換 exception 時,return address 就會被保存到 ELR 暫存器。值得注意的是,EL0 是沒有 ELR 暫存器的,原因是其處於最低的 privilege level,而通常只會有 user mode (EL0) 需要執行 privilege instruction 時需要提昇更高權限的情況發生,提昇權限執行完後會需要 ELR 儲存的返回位置,不會有高權限的 code 執行到一半切到 user mode 後需要紀錄返回位置的情況。 - low privilege level 使用的暫存器寬度不能較 high privilege level 時使用的**大** E.g. 不能在 EL0 使用 64-bit 的暫存器而同時在 EL1 使用 32-bit 的暫存器。 * AArch64 定義四種例外等級: EL0, EL1, EL2, EL3,請找出相關文件 (儘量是 Arm 公司的第一手材料) 並搭配 Linux 核心原始程式碼解說 * [linux-kernel-module-cheat](https://github.com/cirosantilli/linux-kernel-module-cheat) 提及透過 GDB 對 QEMU 模擬的虛擬硬體之上的 Linux 核心進行追蹤和除錯,請解釋具體原理。提示: 應一併說明 GDB stub 和 [QEMU/Debugging with QEMU](https://en.wikibooks.org/wiki/QEMU/Debugging_with_QEMU) 的運作機制 ## 筆記 ### AArch64 #### AArch64 與 AArch32 間之切換 兩者透過 exception 進行切換。需注意 AArch64 無法與 AArch32 交流資訊,也就是說每次切換後處理器不該嘗試使用上個模式暫存器留下的資料等等。 #### 暫存器 - AArch64 的暫存器名為 Xn, 而 AArch32 為 Rn; #### Veneer code 當 linker 發現現存指令(`BL`,最大可跳躍 32MB)無法跳躍到目標 .text section 時,linker 就會插入 Veneer code。Veneer 可想像是一個中繼點,用於幫助跳躍到目標 context 以繼續執行。值得注意的是 Veneer 又有分成三種,以下將簡單說明([詳見](http://www.keil.com/support/man/docs/armlink/armlink_pge1362065915152.htm)): - Inline veneer 僅用於 state change (Thumb mode 與 ARM mode)。僅使用相對位置進行跳躍。 - Short branch veneer 用於 ARM-Thumb 兩個模式間的跳躍。可跳躍距離為 32MB,即為 `BL` (ARM instruction) 之距離。 - Long branch veneer 可任意跳躍。可穿梭於 ARM 與 Thumb 模式之間。可使用絕對位址與相對位址跳躍,須注意如此兩者實做即不同。 #### Kernel 編譯 ##### 第一次編譯 使用 `5.0.7` 版本的 kernel,buildroot 相關設定可參考 [repo](https://github.com/flawless0714/buildroot/tree/aarch64),以下為開機後的畫面截圖: ![](https://i.imgur.com/5vhRXCB.png) ## 參考資料 - [AArch64 暫存器相關](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0801a/BABBGCAC.html) - [Veneer](http://www.keil.com/support/man/docs/armlink/armlink_pge1406301797482.htm) ###### tags: `linux2019`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully