林家葦
    • 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
    # Assignment 3: 林家葦 ###### tags: `Computer Architecture` ## Bubble Sort * **ELF-File** * Check [this page](https://github.com/PulseRain/Reindeer/blob/master/sim/verilator/tb_PulseRain_RV2T.cpp) can find the test file(elf) is generated based on [riscv-compliance](https://github.com/riscv/riscv-compliance) . * And git clone this project to generate ELF file. * **Source code** ```C= #include "compliance_test.h" #include "compliance_io.h" #include "test_macros.h" RV_COMPLIANCE_RV32M RV_COMPLIANCE_CODE_BEGIN RVTEST_IO_INIT RVTEST_IO_ASSERT_GPR_EQ(x31, x0, 0x00000000) RVTEST_IO_WRITE_STR(x31, "Test Begin\n") addi sp,sp,-48 sw s0,44(sp) addi s0,sp,48 la t0,test_1_data lw a5,0(t0) sw a5,-48(s0) la t0,test_2_data lw a5,0(t0) sw a5,-44(s0) la t0,test_3_data lw a5,0(t0) sw a5,-40(s0) la t0,test_4_data lw a5,0(t0) sw a5,-36(s0) la t0,test_5_data lw a5,0(t0) sw a5,-32(s0) sw zero,-20(s0) j .L2 .L6: //ginit j to memory sw zero,-24(s0) j .L3 .L5: //gload arr[ j ] to a4 lw a5,-24(s0) slli a5,a5,2 addi a4,s0,-16 add a5,a4,a5 lw a4,-32(a5) //gload arr[j+1] a5 lw a5,-24(s0) addi a5,a5,1 slli a5,a5,2 addi a3,s0,-16 add a5,a3,a5 lw a5,-32(a5) //gif arr[j + 1] > arr[j] bge a5,a4,.L4 //g arr[j+1] < arr[j] //gload arr[j] a5 lw a5,-24(s0) slli a5,a5,2 addi a4,s0,-16 add a5,a4,a5 lw a5,-32(a5) //gstore arr[j] to tmp sw a5,-28(s0) //gload arr[j+1] to a4 lw a5,-24(s0) addi a5,a5,1 slli a5,a5,2 addi a4,s0,-16 add a5,a4,a5 lw a4,-32(a5) //garr[j] = arr[j+1] lw a5,-24(s0) slli a5,a5,2 addi a3,s0,-16 add a5,a3,a5 sw a4,-32(a5) //gstore tmp to arr[j+1] lw a5,-24(s0) addi a5,a5,1 slli a5,a5,2 addi a4,s0,-16 add a5,a4,a5 lw a4,-28(s0) sw a4,-32(a5) .L4: //gj++ lw a5,-24(s0) addi a5,a5,1 sw a5,-24(s0) .L3: //gcheck (j - i) < 4 li a4,4 lw a5,-20(s0) sub a5,a4,a5 lw a4,-24(s0) blt a4,a5,.L5 //gi++ lw a5,-20(s0) addi a5,a5,1 sw a5,-20(s0) .L2: //gcheck i < 4 lw a4,-20(s0) li a5,3 bge a5,a4,.L6 //greturn lw t0, -48(s0) la t1, test_1_res sw t0, 0(t1) lw t0,-44(s0) sw t0, 4(t1) lw t0,-40(s0) sw t0, 8(t1) lw t0,-36(s0) sw t0, 12(t1) lw t0,-32(s0) sw t0, 16(t1) li a5,0 mv a0,a5 lw s0,44(sp) addi sp,sp,48 jr ra RVTEST_IO_WRITE_STR(x31, "Test End\n") RV_COMPLIANCE_HALT RV_COMPLIANCE_CODE_END .data test_1_data : .word 0x00000003 test_2_data : .word 0x00000005 test_3_data : .word 0x00000001 test_4_data : .word 0x00000002 test_5_data : .word 0x00000004 RV_COMPLIANCE_DATA_BEGIN test_1_res: .fill 5, 4, -1 RV_COMPLIANCE_DATA_END ``` * **Compiler source code** ``` $ cd riscv-compliance/riscv-test-suite/rv32i $ make bubble.elf riscv-none-embed-gcc -march=rv32i -mabi=ilp32 -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -I../..//riscv-test-env/ -I../..//riscv-test-env/p/ -I../../riscv-target//riscvOVPsim/ -T../..//riscv-test-env/p/link.ld src/T.S -o ../..//work//T.elf; riscv-none-embed-objdump -D ../..//work//T.elf > ../..//work//T.elf.objdump ``` * **Execute** ``` $ make build $ make test T ====> Testing ./obj_dir/VPulseRain_RV2T_MCU TEST CASE: T testing ../compliance/T.elf -r ../compliance/references/T.reference_output ============================================================= === PulseRain Technology, RISC-V RV32IM Test Bench ============================================================= elf file : ../compliance/T.elf reference : ../compliance/references/T.reference_output start address = 0x80000000 begin signature address = 0x80002020 end signature address = 0x80002040 =============> reset... =============> init stack ... =============> load elf file... ... ... ... ========> Matching signature ... 80002020 00000001 PASS 80002024 00000002 PASS 80002028 00000003 PASS 8000202c 00000004 PASS 80002030 00000005 PASS ======> Signature ALL MATCH!!! ``` * **Memory Layout** ![](https://i.imgur.com/lwmLSlp.png) ## GTKwave 1. Reset the CPU, put it into hold state and it will have access to the UART TX port by default. But a valid debug frame sending from the host PC can let OCD to reconfigure the mux and switch the UART TX to OCD side, for which the memory can be accessed, and the control frames can be exchanged ![](https://i.imgur.com/gq8uuBE.png) 2. Call upon toolchain to extract code/data from the .elf file for the test case and OCD will load binary code into Memory, and the cpu will be paused. ![](https://i.imgur.com/M6TxIBf.png) ``` Loading section .text.init ... 2c4 bytes, LMA = 0x80000000 80000000 04c0006f 80000004 34202f73 80000008 00800f93 8000000c 03ff0a63 80000010 00900f93 80000014 03ff0663 80000018 00b00f93 8000001c 03ff0263 80000020 80000f17 80000024 fe0f0f13 80000028 000f0463 8000002c 000f0067 80000030 34202f73 80000034 000f5463 80000038 0040006f 8000003c 5391e193 80000040 00001f17 80000044 fc3f2023 80000048 ff9ff06f 8000004c f1402573 80000050 00051063 80000054 00000297 80000058 01028293 ``` 3. When OCD load whole code/data into memory, it will arise start signal to wake up the CPU. ![](https://i.imgur.com/vys95Xh.png) 4. Start execute the program ![](https://i.imgur.com/hRduwkf.png) 5. When CPU finishes the program, resetting the CPU, put it into hold state for the second time ![](https://i.imgur.com/Mu02NIj.png) 6. Read the data out of the memory, and compare them against the reference signature ![](https://i.imgur.com/ISpDOV3.png) ## How Reindeer works with Verilator Verilator is a free and open-source software tool which converts Verilog (a hardware description language) to a cycle-accurate behavioral model in C++ or SystemC. And Obesve sim/verilator/tb_PulseRain_RV2T.cpp ```cpp uut = new UUT; // Create instance VerilatedVcdC* tfp = new VerilatedVcdC; ``` The uut which is object is also soft cpu. We simulate hold and wait and initialize the register. ```cpp if (!trace_file.empty()) { Verilated::traceEverOn(true); uut->trace (tfp, 99); tfp->open (trace_file.c_str()); } else { tfp = NULL; } testbench t {10, uut, tfp}; uut->reset_n = 0; // Set some inputs uut->sync_reset = 0; std::cout << "\n=============> reset..." << "\n"; uut->sync_reset = 0; uut->ocd_reg_we = 0; uut->ocd_reg_read_addr = 0; uut->ocd_reg_write_addr = 0; uut->ocd_reg_write_data = 0; uut->ocd_read_enable = 0; uut->ocd_write_enable = 0; uut->ocd_rw_addr = 0; uut->ocd_write_word = 0; uut->start = 0; uut->start_address = start_address; t.reset(); std::cout << "=============> init stack ..." << "\n"; uut->ocd_reg_we = 1; uut->ocd_reg_write_addr = 2; // SP uut->ocd_reg_write_data = DEFAULT_STACK_INIT_VALUE; t.run(); uut->ocd_reg_we = 0; t.run(); std::cout << "=============> load elf file..." << "\n"; load_elf_sections(&t, uut); t.run(); ``` When the OCD loads program into memory. The start signal will be arised, and the circuit will start to execute the program. ```cpp load_elf_sections(&t, uut); t.run(); std::cout << "\n=============> start running ..." << "\n"; uut->start = 1; t.run(); uut->start = 0; t.run(); ``` ## Hold and Load ![](https://i.imgur.com/SsIjTrE.png) After reset, the soft CPU will be put into a hold state, and it will have access to the UART TX port by default. But a valid debug frame sending from the host PC can let OCD to reconfigure the mux and switch the UART TX to OCD side, for which the memory can be accessed, and the control frames can be exchanged. A new software image can be loaded into the memory during the CPU hold state, which gives rise to the name "hold-and-load".

    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