Skip to content

Commit d5fbf92

Browse files
committed
Merge branch 'dev/ebl/dj_backport' into dev/ebl/eg-v9.2.0
2 parents ae35f03 + 978c293 commit d5fbf92

File tree

383 files changed

+94805
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

383 files changed

+94805
-245
lines changed

.github/workflows/build_test.yaml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
---
2+
#------------------------------------------------------------------------------
3+
# QEMU OpenTitan CI
4+
#
5+
# Copyright (c) 2023-2025 Rivos, Inc.
6+
# SPDX-License-Identifier: Apache License 2.0
7+
#------------------------------------------------------------------------------
8+
9+
name: Build & Test QEMU OT
10+
on: [pull_request]
11+
jobs:
12+
build-clang:
13+
runs-on: ubuntu-24.04
14+
steps:
15+
- name: Install deps
16+
run: |
17+
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key |
18+
sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc &&
19+
sudo add-apt-repository "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main" &&
20+
sudo apt-get update &&
21+
sudo apt-get install -y git make pkg-config clang-18 cmake ninja-build python3 rust-all \
22+
libpixman-1-dev libglib2.0-dev
23+
- name: Check out QEMU
24+
uses: actions/checkout@v4
25+
- name: Configure
26+
run: |
27+
rm -rf build-clang
28+
git clean -dffx subprojects
29+
mkdir build-clang
30+
(cd build-clang &&
31+
../configure --cc=clang-18 --disable-werror --disable-install-blobs \
32+
--target-list=riscv32-softmmu,riscv64-softmmu)
33+
- name: Build
34+
run: |
35+
ninja -C build-clang &&
36+
ninja -C build-clang qemu-img &&
37+
strip build-clang/qemu-system-riscv32
38+
- name: Create minimal test binaries
39+
run: |
40+
scripts/opentitan/swexit.py -t ibexdemo -b 0x0 -o build-clang/exit_id.bin
41+
scripts/opentitan/swexit.py -t earlgrey -b 0x80 -o build-clang/exit_eg.bin
42+
scripts/opentitan/swexit.py -t darjeeling -b 0x80 -o build-clang/exit_dj.bin
43+
- name: Upload QEMU binary artifacts
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: qemu-bin
47+
path: |
48+
build-clang/qemu-system-riscv32
49+
build-clang/exit_*.bin
50+
retention-days: 1
51+
- name: Pack source artifacts
52+
# GitHub takes ages to retrieve each source file, so pack them
53+
run: |
54+
tar czf qemu-src-artifact.tar.gz \
55+
subprojects/libtomcrypt/src/headers/*.h \
56+
build-clang/*.h \
57+
build-clang/qapi/*.h \
58+
build-clang/trace/*.h \
59+
build-clang/compile_commands.json
60+
- name: Upload QEMU source artifacts
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: qemu-src
64+
path: qemu-src-artifact.tar.gz
65+
retention-days: 1
66+
67+
format:
68+
runs-on: ubuntu-24.04
69+
steps:
70+
- name: Install tools
71+
run: |
72+
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key |
73+
sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc &&
74+
sudo add-apt-repository "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main" &&
75+
sudo apt-get update &&
76+
sudo apt-get install -y clang-format-18
77+
- name: Check out QEMU
78+
uses: actions/checkout@v4
79+
- name: Check C code format
80+
run: |
81+
scripts/opentitan/ot-format.sh --ci -i
82+
83+
lint-python:
84+
runs-on: ubuntu-latest
85+
steps:
86+
- name: Install tools
87+
run: |
88+
sudo apt-get update &&
89+
sudo apt-get install -y python3-pip
90+
# ubuntu "latest" is too old to require --break-system-packages ...
91+
pip3 install pylint==3.3.3
92+
- name: Check out QEMU
93+
uses: actions/checkout@v4
94+
- name: Lint Python code
95+
run: |
96+
pylint --rcfile scripts/opentitan/.pylintrc -d 'duplicate-code' -d 'fixme' \
97+
scripts/opentitan/*.py python/qemu/jtagtools python/qemu/ot
98+
99+
lint-clang:
100+
runs-on: ubuntu-24.04
101+
needs: build-clang
102+
steps:
103+
- name: Install tools
104+
run: |
105+
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key |
106+
sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc &&
107+
sudo add-apt-repository "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main" &&
108+
sudo apt-get update &&
109+
sudo apt-get install -y clang-tidy-18 libglib2.0-dev
110+
- name: Check out QEMU
111+
uses: actions/checkout@v4
112+
- name: Download QEMU source artifacts
113+
uses: actions/download-artifact@v4
114+
with:
115+
name: qemu-src
116+
- name: Unpack source artifacts
117+
run: |
118+
tar xzf qemu-src-artifact.tar.gz
119+
- name: Clang tidy
120+
# Expect many warnings/errors (accounted but not reported) from included QEMU files
121+
run: |
122+
scripts/opentitan/ot-tidy.sh --ci -p build-clang
123+
124+
lint-commits:
125+
runs-on: ubuntu-latest
126+
steps:
127+
- uses: actions/checkout@v4
128+
with:
129+
fetch-depth: 0 # Don't shallow clone, we need to see all commits.
130+
- name: Lint commits
131+
run: ./scripts/opentitan/lint-commits.sh "origin/${{ github.base_ref }}"
132+
133+
test-clang:
134+
runs-on: ubuntu-24.04
135+
needs: build-clang
136+
steps:
137+
- name: Install tools
138+
run: |
139+
sudo apt-get update &&
140+
sudo apt-get install -y libpixman-1-0 libglib2.0-dev
141+
- name: Download QEMU binary artifacts
142+
uses: actions/download-artifact@v4
143+
with:
144+
name: qemu-bin
145+
- name: Check machine availability
146+
run: |
147+
chmod +x ./qemu-system-riscv32 &&
148+
./qemu-system-riscv32 -M help | grep ibexdemo &&
149+
./qemu-system-riscv32 -M help | grep ot-earlgrey &&
150+
./qemu-system-riscv32 -M help | grep ot-darjeeling
151+
- name: Check IbexDemo VM execution
152+
run: |
153+
timeout -s KILL 4 ./qemu-system-riscv32 -M ibexdemo -nographic \
154+
-device loader,addr=0x100080,file=exit_id.bin -d in_asm,int
155+
- name: Check EarlGrey VM execution
156+
run: |
157+
timeout -s KILL 4 ./qemu-system-riscv32 -M ot-earlgrey,no_epmp_cfg=true -nographic \
158+
-object ot-rom_img,id=rom,file=exit_eg.bin -d in_asm,int
159+
160+
build-gcc:
161+
runs-on: ubuntu-24.04
162+
steps:
163+
- name: Install tools
164+
run: |
165+
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key |
166+
sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc &&
167+
sudo add-apt-repository "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main" &&
168+
sudo apt-get update &&
169+
sudo apt-get install -y git make pkg-config gcc cmake ninja-build python3 rust-all \
170+
libpixman-1-dev libglib2.0-dev
171+
- name: Check out QEMU
172+
uses: actions/checkout@v4
173+
- name: Configure
174+
run: |
175+
rm -rf build-gcc
176+
git clean -dffx subprojects
177+
mkdir build-gcc
178+
(cd build-gcc &&
179+
../configure --cc=gcc --enable-werror --disable-install-blobs \
180+
--target-list=riscv32-softmmu,riscv64-softmmu)
181+
- name: Build
182+
run: |
183+
ninja -C build-gcc
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Create Release
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
release_tag:
6+
required: true
7+
type: string
8+
9+
jobs:
10+
release:
11+
permissions:
12+
# Necessary permissions to create a release.
13+
contents: write
14+
env:
15+
BUILD_DIR: build
16+
BRANCH_NAME: ${{ github.event.repository.default_branch }}
17+
RELEASE_BIN_ARCHIVE: qemu-ot-earlgrey-${{ inputs.release_tag }}-x86_64-unknown-linux-gnu.tar.gz
18+
runs-on: ubuntu-22.04
19+
timeout-minutes: 10
20+
steps:
21+
- name: Check out repository
22+
uses: actions/checkout@v3
23+
# Update the package index, then install all dependencies listed in
24+
# the various apt-requirements.txt files in the project.
25+
- name: Install Dependencies
26+
run: |
27+
sudo apt-get update
28+
sudo apt-get install -y ninja-build libpixman-1-dev
29+
- name: Configure
30+
run: |
31+
mkdir "$BUILD_DIR"
32+
cd "$BUILD_DIR"
33+
../configure --target-list=riscv32-softmmu --without-default-features --enable-tcg \
34+
--enable-tools --enable-trace-backends=log
35+
- name: Build
36+
run: |
37+
cd "$BUILD_DIR"
38+
ninja
39+
ninja qemu-img
40+
- name: Create binary archive
41+
run: |
42+
./scripts/opentitan/make_release.sh "$RELEASE_BIN_ARCHIVE" . "$BUILD_DIR"
43+
- name: Create release
44+
env:
45+
GH_TOKEN: ${{ github.token }}
46+
run: |
47+
gh release create \
48+
--target "$BRANCH_NAME" \
49+
${{ inputs.release_tag }} \
50+
--generate-notes \
51+
"$RELEASE_BIN_ARCHIVE#QEMU system emulator"

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
.sdk
77
.stgit-*
88
.git-submodule-status
9-
.clang-format
109
.gdb_history
1110
cscope.*
1211
tags
@@ -20,3 +19,9 @@ GTAGS
2019
*.swp
2120
*.patch
2221
*.gcov
22+
subprojects/*-*/
23+
subprojects/libtomcrypt/
24+
subprojects/packagecache/
25+
!subprojects/packagefiles/**/*.patch
26+
hw/opentitan/otbn/otbn/Cargo.lock
27+
hw/opentitan/otbn/otbn/target/

MAINTAINERS

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,14 +1576,41 @@ F: pc-bios/vof*
15761576

15771577
RISC-V Machines
15781578
---------------
1579+
1580+
EarlGrey and Darjeeling OpenTitan platforms
1581+
M: Emmanuel Blot <[email protected]>
1582+
M: Loïc Lefort <[email protected]>
1583+
S: Supported
1584+
F: hw/opentitan/*
1585+
F: include/hw/opentitan/*
1586+
F: scripts/opentitan/*
1587+
F: hw/riscv/ot_darjeeling.c
1588+
F: hw/riscv/ot_earlgrey.c
1589+
F: include/hw/riscv/ot_darjeeling.h
1590+
F: include/hw/riscv/ot_earlgrey.h
1591+
1592+
Ibex platforms and utilities
1593+
M: Emmanuel Blot <[email protected]>
1594+
M: Loïc Lefort <[email protected]>
1595+
S: Supported
1596+
F: hw/riscv/ibex_common.c
1597+
F: include/hw/riscv/ibex_common.h
1598+
F: include/hw/riscv/ibex_irq.h
1599+
F: hw/ibexdemo/*
1600+
F: include/hw/ibexdemo/*
1601+
15791602
OpenTitan
15801603
M: Alistair Francis <[email protected]>
15811604
15821605
S: Supported
15831606
F: hw/riscv/opentitan.c
1584-
F: hw/*/ibex_*.c
1607+
F: hw/ssi/ibex_spi_host.c
1608+
F: hw/timer/ibex_timer.c
1609+
F: hw/char/ibex_uart.c
15851610
F: include/hw/riscv/opentitan.h
1586-
F: include/hw/*/ibex_*.h
1611+
F: include/hw/ssi/ibex_spi_host.h
1612+
F: include/hw/timer/ibex_timer.h
1613+
F: include/hw/char/ibex_uart.h
15871614

15881615
Microchip PolarFire SoC Icicle Kit
15891616
M: Bin Meng <[email protected]>

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# QEMU OpenTitan README
2+
3+
[![.github/workflows/build_test.yaml](https://github.com/lowRISC/qemu/actions/workflows/build_test.yaml/badge.svg?branch=ot-earlgrey-9.1.0)](https://github.com/lowRISC/qemu/actions/workflows/build_test.yaml)
4+
5+
QEMU is a generic and open source machine & userspace emulator and virtualizer.
6+
7+
QEMU is capable of emulating a complete machine in software without any need for hardware
8+
virtualization support. By using dynamic translation, it achieves very good performance.
9+
10+
This branch contains a fork of QEMU 9.1.0 dedicated to support lowRISC Ibex platforms:
11+
* [OpenTitan](https://opentitan.org) [EarlGrey](docs/opentitan/earlgrey.md) with FPGA "Bergen Board"
12+
CW310 memory map.
13+
* [lowRISC](https://github.com/lowRISC/ibex-demo-system) [IbexDemo](ibexdemo.md) with Digilent Arty7
14+
board memory map.
15+
16+
See [installation instructions](docs/opentitan/index.md)
17+
18+
See also original [QEMU README file](README_QEMU.rst)
File renamed without changes.

accel/tcg/cpu-exec.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
677677
static inline bool cpu_handle_halt(CPUState *cpu)
678678
{
679679
#ifndef CONFIG_USER_ONLY
680+
if (unlikely(cpu->held_in_reset)) {
681+
return true;
682+
}
683+
680684
if (cpu->halted) {
681685
const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops;
682686
bool leave_halt = tcg_ops->cpu_exec_halt(cpu);
@@ -727,6 +731,10 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
727731
*ret = cpu->exception_index;
728732
if (*ret == EXCP_DEBUG) {
729733
cpu_handle_debug_exception(cpu);
734+
if (cpu->exception_index < 0) {
735+
/* the handler has cleared the exception */
736+
return false;
737+
}
730738
}
731739
cpu->exception_index = -1;
732740
return true;
@@ -1019,6 +1027,13 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
10191027
tb_add_jump(last_tb, tb_exit, tb);
10201028
}
10211029

1030+
if (unlikely((cflags != -1) && (cflags & CF_SINGLE_STEP))) {
1031+
CPUClass *cc = cpu->cc;
1032+
if (cc->debug_enable_singlestep) {
1033+
cc->debug_enable_singlestep(cpu, pc);
1034+
}
1035+
}
1036+
10221037
cpu_loop_exec_tb(cpu, tb, pc, &last_tb, &tb_exit);
10231038

10241039
/* Try to align the host and virtual clocks

accel/tcg/tb-maint.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc)
10841084
if (current_tb_modified) {
10851085
/* Force execution of one insn next time. */
10861086
CPUState *cpu = current_cpu;
1087-
cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
1087+
cpu->cflags_next_tb =
1088+
1 | CF_NOIRQ | curr_cflags(current_cpu);
10881089
return true;
10891090
}
10901091
return false;
@@ -1154,7 +1155,8 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,
11541155
if (current_tb_modified) {
11551156
page_collection_unlock(pages);
11561157
/* Force execution of one insn next time. */
1157-
current_cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
1158+
current_cpu->cflags_next_tb =
1159+
1 | CF_NOIRQ | curr_cflags(current_cpu);
11581160
mmap_unlock();
11591161
cpu_loop_exit_noexc(current_cpu);
11601162
}

configs/devices/riscv32-softmmu/default.mak

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@
99
# CONFIG_SIFIVE_E=n
1010
# CONFIG_SIFIVE_U=n
1111
# CONFIG_RISCV_VIRT=n
12-
# CONFIG_OPENTITAN=n
12+
13+
CONFIG_SPIKE=y
14+
CONFIG_SIFIVE_E=y
15+
CONFIG_SIFIVE_U=y
16+
CONFIG_RISCV_VIRT=y
17+
CONFIG_IBEXDEMO=y
18+
CONFIG_OT_DARJEELING=y
19+
CONFIG_OT_EARLGREY=y
20+
CONFIG_OPENTITAN=n

disas/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ common_ss.add(when: 'CONFIG_MIPS_DIS', if_true: files('mips.c', 'nanomips.c'))
77
common_ss.add(when: 'CONFIG_RISCV_DIS', if_true: files(
88
'riscv.c',
99
'riscv-xthead.c',
10-
'riscv-xventana.c'
10+
'riscv-xventana.c',
11+
'riscv-zbr.c'
1112
))
1213
common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c'))
1314
common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c'))

0 commit comments

Comments
 (0)