-
Notifications
You must be signed in to change notification settings - Fork 195
Add qemu CI #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
KushalMeghani1644
wants to merge
57
commits into
rust-embedded:master
from
KushalMeghani1644:add-qemu-ci
Closed
Add qemu CI #372
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
2f85419
Implement VSTOPI CSR for RISC-V
KushalMeghani1644 770334a
Update CHANGELOG.md
KushalMeghani1644 f2149a3
Add qemu CI
KushalMeghani1644 105c9f4
Improve QEMU CI
KushalMeghani1644 ec4e7d4
Fix QEMU CI
KushalMeghani1644 b92ec05
Fix QEMU CI
KushalMeghani1644 7d0d8df
Update QEMU CI
KushalMeghani1644 17d9bed
Fix package issue
KushalMeghani1644 3637239
Add QEMU CI to add expected hello outputs
KushalMeghani1644 8567f5f
Fix qemu CI
KushalMeghani1644 0078ff2
Fix formatting
KushalMeghani1644 1731bdf
Fix QEMU CI for a clean output ensuring the CI passes
KushalMeghani1644 2aba7b3
Updated tests to use riscv-semihosting instead of UART
KushalMeghani1644 7524ed5
Added one test using UART and one test with riscv-semihosting
KushalMeghani1644 522e17d
Update CHANGELOG.md
KushalMeghani1644 71b69f5
Update types.toml
KushalMeghani1644 a31f5fb
Fix UB in heap init example docs
kurtjd 7db26ba
Merge pull request #376 from kurtjd/fix-example-ub
romancardenas 86f649d
Merge pull request #373 from KushalMeghani1644/add-vstopi
romancardenas 4d46022
Fix v-trap core interrupt
kurtjd 297e3d5
Merge pull request #377 from kurtjd/vtrap-isa-panic
romancardenas 19734b6
Update riscv-rt/examples/hello.rs
KushalMeghani1644 4c9a345
Update riscv-rt/examples/hello.rs
KushalMeghani1644 c624883
Update riscv-rt/CHANGELOG.md
KushalMeghani1644 22fe9e3
Update xtask/src/main.rs
KushalMeghani1644 cfe87db
Address review comments
KushalMeghani1644 7bc230b
fix formatting
KushalMeghani1644 f5a08ce
Add expected QEMU CI files
KushalMeghani1644 e5f4af1
Add qemu CI
KushalMeghani1644 2deec5b
Improve QEMU CI
KushalMeghani1644 37111be
Fix QEMU CI
KushalMeghani1644 388cb8b
Fix QEMU CI
KushalMeghani1644 2a42ead
Update QEMU CI
KushalMeghani1644 2cc11f8
Fix package issue
KushalMeghani1644 1c1abd5
Add QEMU CI to add expected hello outputs
KushalMeghani1644 62bd0fb
Fix qemu CI
KushalMeghani1644 0792729
Fix formatting
KushalMeghani1644 bb8684e
Fix QEMU CI for a clean output ensuring the CI passes
KushalMeghani1644 eca57eb
Updated tests to use riscv-semihosting instead of UART
KushalMeghani1644 6c48a60
Added one test using UART and one test with riscv-semihosting
KushalMeghani1644 66410a1
Update CHANGELOG.md
KushalMeghani1644 fabc4cd
Update types.toml
KushalMeghani1644 6bd28fc
Update riscv-rt/examples/hello.rs
KushalMeghani1644 9288569
Update riscv-rt/examples/hello.rs
KushalMeghani1644 5a8fd70
Update riscv-rt/CHANGELOG.md
KushalMeghani1644 1809192
Update xtask/src/main.rs
KushalMeghani1644 e516f04
Address review comments
KushalMeghani1644 e8e6847
fix formatting
KushalMeghani1644 1dab284
Add expected QEMU CI files
KushalMeghani1644 4cbabfa
Simplify QEMU CI by consolidating golden files and using
KushalMeghani1644 d56564b
Remove uneeded file
KushalMeghani1644 1e4763a
resolve conflict
KushalMeghani1644 7eed218
fix lints
KushalMeghani1644 de5e0b9
Remove conflicts
KushalMeghani1644 7fbdf5a
Fix QEMU CI
KushalMeghani1644 5b4b717
Remove duplicates in code
KushalMeghani1644 4bede74
Remove uneeded files
KushalMeghani1644 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: QEMU tests | ||
| on: | ||
| merge_group: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| env: | ||
| CARGO_TERM_COLOR: always | ||
|
|
||
| jobs: | ||
| testexamples: | ||
| name: QEMU run | ||
| runs-on: ubuntu-24.04 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| toolchain: [stable] | ||
| target-qemu: | ||
| - target: riscv32i-unknown-none-elf | ||
| qemu: riscv32 | ||
| - target: riscv32im-unknown-none-elf | ||
| qemu: riscv32 | ||
| - target: riscv32imc-unknown-none-elf | ||
| qemu: riscv32 | ||
| - target: riscv32imac-unknown-none-elf | ||
| qemu: riscv32 | ||
| - target: riscv32imafc-unknown-none-elf | ||
| qemu: riscv32 | ||
| - target: riscv64imac-unknown-none-elf | ||
| qemu: riscv64 | ||
| - target: riscv64gc-unknown-none-elf | ||
| qemu: riscv64 | ||
| example: | ||
| - qemu_uart | ||
| - qemu_semihosting | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Configure Rust target ${{ matrix.target-qemu.target }} | ||
| run: | | ||
| rustup toolchain install ${{ matrix.toolchain }} | ||
| rustup default ${{ matrix.toolchain }} | ||
| rustup target add ${{ matrix.target-qemu.target }} | ||
|
|
||
| - name: Cache Dependencies | ||
| uses: Swatinem/rust-cache@v2 | ||
|
|
||
| - name: Install QEMU | ||
| run: | | ||
| sudo apt update | ||
| sudo apt install -y qemu-system-${{ matrix.target-qemu.qemu }} | ||
|
|
||
| - name: Run-pass tests | ||
| run: cargo run --package xtask -- qemu --target ${{ matrix.target-qemu.target }} --example ${{ matrix.example }} | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ members = [ | |
| "riscv-types", | ||
| "tests-build", | ||
| "tests-trybuild", | ||
| "xtask", | ||
| ] | ||
|
|
||
| default-members = [ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Hello from semihosting! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Hello from UART! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| MEMORY | ||
| { | ||
| RAM : ORIGIN = 0x80000000, LENGTH = 16M | ||
| } | ||
| REGION_ALIAS("REGION_TEXT", RAM); | ||
| REGION_ALIAS("REGION_RODATA", RAM); | ||
| REGION_ALIAS("REGION_DATA", RAM); | ||
| REGION_ALIAS("REGION_BSS", RAM); | ||
| REGION_ALIAS("REGION_HEAP", RAM); | ||
| REGION_ALIAS("REGION_STACK", RAM); | ||
| INCLUDE link.x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //! Semihosting example for QEMU | ||
| //! | ||
| //! This example uses RISC-V semihosting to print output and cleanly exit QEMU. | ||
| //! Run with: `qemu-system-riscv32 -machine virt -nographic -semihosting-config enable=on,target=native -bios none -kernel <binary>` | ||
|
|
||
| #![no_std] | ||
| #![no_main] | ||
|
|
||
| extern crate panic_halt; | ||
|
|
||
| use riscv_rt::entry; | ||
| use riscv_semihosting::{ | ||
| debug::{self, EXIT_SUCCESS}, | ||
| hprintln, | ||
| }; | ||
|
|
||
| #[entry] | ||
| fn main() -> ! { | ||
| hprintln!("Hello from semihosting!"); | ||
| debug::exit(EXIT_SUCCESS); | ||
| loop {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| //! UART example for QEMU virt machine | ||
|
KushalMeghani1644 marked this conversation as resolved.
|
||
| //! | ||
| //! This example demonstrates direct UART output on QEMU's virt machine. | ||
| //! It writes to the NS16550-compatible UART at 0x1000_0000. | ||
|
|
||
| #![no_std] | ||
| #![no_main] | ||
|
|
||
| extern crate panic_halt; | ||
|
|
||
| use riscv_rt::entry; | ||
|
KushalMeghani1644 marked this conversation as resolved.
|
||
| use riscv_semihosting::debug::{self, EXIT_SUCCESS}; | ||
|
|
||
| const UART_BASE: usize = 0x1000_0000; | ||
| const UART_THR: usize = UART_BASE; | ||
| const UART_IER: usize = UART_BASE + 1; | ||
| const UART_FCR: usize = UART_BASE + 2; | ||
| const UART_LCR: usize = UART_BASE + 3; | ||
| const UART_LSR: usize = UART_BASE + 5; | ||
| const LCR_DLAB: u8 = 1 << 7; | ||
| const LCR_8N1: u8 = 0x03; | ||
| const LSR_THRE: u8 = 1 << 5; | ||
|
|
||
| unsafe fn uart_write_reg(off: usize, v: u8) { | ||
| (off as *mut u8).write_volatile(v); | ||
| } | ||
|
|
||
| unsafe fn uart_read_reg(off: usize) -> u8 { | ||
| (off as *const u8).read_volatile() | ||
| } | ||
|
|
||
| fn uart_init() { | ||
| unsafe { | ||
| uart_write_reg(UART_LCR, LCR_DLAB); | ||
| uart_write_reg(UART_THR, 0x01); | ||
| uart_write_reg(UART_IER, 0x00); | ||
| uart_write_reg(UART_LCR, LCR_8N1); | ||
| uart_write_reg(UART_FCR, 0x07); | ||
| } | ||
| } | ||
|
|
||
| fn uart_write_byte(b: u8) { | ||
| unsafe { | ||
| while (uart_read_reg(UART_LSR) & LSR_THRE) == 0 {} | ||
| uart_write_reg(UART_THR, b); | ||
| } | ||
| } | ||
|
|
||
| fn uart_write_str(s: &str) { | ||
| for &b in s.as_bytes() { | ||
| uart_write_byte(b); | ||
| } | ||
| } | ||
|
|
||
| #[entry] | ||
| fn main() -> ! { | ||
| uart_init(); | ||
| uart_write_str("Hello from UART!\n"); | ||
| debug::exit(EXIT_SUCCESS); | ||
| loop {} | ||
|
KushalMeghani1644 marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| //! vstopi register — Virtual Supervisor Top Priority Interrupt (0xEB0) | ||
|
|
||
| read_only_csr! { | ||
| /// Virtual Supervisor Top Priority Interrupt Register | ||
| Vstopi: 0xEB0, | ||
| mask: 0x0FFF_00FF, | ||
| } | ||
|
|
||
| read_only_csr_field! { | ||
| Vstopi, | ||
| /// Interrupt ID (bits 16..27) | ||
| /// | ||
| /// Identifies the specific interrupt source. A value of 0 indicates no interrupt is pending. | ||
| /// Non-zero values correspond to specific interrupt sources as defined by the interrupt controller. | ||
| iid: [16:27], | ||
| } | ||
|
|
||
| read_only_csr_field! { | ||
| Vstopi, | ||
| /// Interrupt Priority ID (bits 0..7) | ||
| /// | ||
| /// Represents the priority level of the pending interrupt. | ||
| /// Lower numerical values indicate higher priority interrupts. | ||
| iprio: [0:7], | ||
| } | ||
|
|
||
| impl Vstopi { | ||
| /// Returns true if there is a valid interrupt pending | ||
| /// | ||
| /// When this returns true, both `interrupt_id()` and `priority()` will return meaningful values. | ||
| #[inline] | ||
| pub fn is_interrupt_pending(&self) -> bool { | ||
| self.iid() != 0 | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_vstopi_fields() { | ||
| let vstopi = Vstopi::from_bits(0); | ||
| test_ro_csr_field!(vstopi, iid: [16, 27], 0x0); | ||
| test_ro_csr_field!(vstopi, iprio: [0, 7], 0x0); | ||
|
|
||
| let vstopi = Vstopi::from_bits((0xB << 16) | 5); | ||
| test_ro_csr_field!(vstopi, iid: [16, 27], 0xB); | ||
| test_ro_csr_field!(vstopi, iprio: [0, 7], 0x5); | ||
|
|
||
| let vstopi = Vstopi::from_bits((0xFFF << 16) | 0xFF); | ||
| test_ro_csr_field!(vstopi, iid: [16, 27], 0xFFF); | ||
| test_ro_csr_field!(vstopi, iprio: [0, 7], 0xFF); | ||
|
|
||
| let vstopi = Vstopi::from_bits(1 << 16); | ||
| test_ro_csr_field!(vstopi, iid: [16, 27], 0x1); | ||
| test_ro_csr_field!(vstopi, iprio: [0, 7], 0x0); | ||
|
|
||
| let vstopi = Vstopi::from_bits(1); | ||
| test_ro_csr_field!(vstopi, iid: [16, 27], 0x0); | ||
| test_ro_csr_field!(vstopi, iprio: [0, 7], 0x1); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_vstopi_bitmask() { | ||
| let vstopi = Vstopi::from_bits(usize::MAX); | ||
| assert_eq!(vstopi.bits(), 0x0FFF_00FFusize); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| [default] | ||
| extend-ignore-re = ["[Ss][Ii][Ee]", "[Ss][Xx][Ll]", "[.]?useed[.,:]?", "[Ss][Tt][Ii][Pp]"] | ||
| extend-ignore-words-re = ["[Pp]endings", "PENDINGS"] | ||
| extend-ignore-words-re = ["[Pp]endings", "PENDINGS", "THR", "THRE"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [package] | ||
| name = "xtask" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| anyhow = "1" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This forces us to only test for single-core devices. It is ok for the time being, but we should think of a more versatile way to allow us to test multi-core devices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to address this ASAP!