Skip to content

Tracewrap 8.1 #32

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

Merged
merged 124 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
5980189
target/s390x: Fix the "ignored match" case in VSTRS
iii-i Aug 4, 2023
880e82e
target/s390x: Use a 16-bit immediate in VREP
iii-i Aug 7, 2023
c12eddb
target/s390x: Fix VSTL with a large length
iii-i Aug 4, 2023
14a8213
target/s390x: Check reserved bits of VFMIN/VFMAX's M5
iii-i Aug 4, 2023
01f6417
include/hw/virtio/virtio-gpu: Fix virtio-gpu with blob on big endian …
huth Aug 15, 2023
34808d0
kvm: Introduce kvm_arch_get_default_type hook
akihikodaki Aug 22, 2023
c8e381d
accel/kvm: Specify default IPA size for arm64
akihikodaki Aug 22, 2023
7012e20
target/arm: Fix SME ST1Q
rth7680 Aug 22, 2023
63188a0
target/arm: Fix 64-bit SSRA
rth7680 Aug 22, 2023
441106e
docs/about/license: Update LICENSE URL
philmd Aug 22, 2023
5691fbf
softmmu: Assert data in bounds in iotlb_to_section
rth7680 Aug 25, 2023
86d7b08
block-migration: Ensure we don't crash during migration cleanup
Jul 31, 2023
645b87f
target/arm: properly document FEAT_CRC32
stsquad Aug 31, 2023
e5e77f2
linux-user: Adjust brk for load_bias
rth7680 Aug 16, 2023
e975434
target/i386: raise FERR interrupt with iothread locked
bonzini Aug 29, 2023
0175121
ui/dbus: Properly dispose touch/mouse dbus objects
bilelmoussaoui Sep 1, 2023
6864f05
ppc/vof: Fix missed fields in VOF cleanup
npiggin Aug 8, 2023
5358980
hw/ppc/e500: fix broken snapshot replay
Aug 9, 2023
9f54fef
target/ppc: Flush inputs to zero with NJ in ppc_store_vscr
rth7680 Aug 21, 2023
f64f1f8
target/ppc: Fix LQ, STQ register-pair order for big-endian
npiggin Aug 21, 2023
c2e0495
hw/ide/core: set ERR_STAT in unsupported command completion
Jun 9, 2023
1efefd1
hw/ide/ahci: write D2H FIS when processing NCQ command
Jun 9, 2023
16cc959
hw/ide/ahci: simplify and document PxCI handling
Jun 9, 2023
4fbd5a5
hw/ide/ahci: PxSACT and PxCI is cleared when PxCMD.ST is cleared
Jun 9, 2023
4448c34
hw/ide/ahci: PxCI should not get cleared when ERR_STAT is set
Jun 9, 2023
e8f5ca5
hw/ide/ahci: fix ahci_write_fis_sdb()
Jun 9, 2023
d536158
hw/ide/ahci: fix broken SError handling
Jun 9, 2023
9dc6f05
hw/i2c/aspeed: Fix Tx count and Rx size error in buffer pool mode
Aug 12, 2023
25ec23a
hw/i2c/aspeed: Fix TXBUF transmission start position error
Aug 12, 2023
01bf87c
qemu-options.hx: Rephrase the descriptions of the -hd* and -cdrom opt…
huth Aug 29, 2023
6356785
docs tests: Fix use of migrate_set_parameter
Aug 25, 2023
93d4107
hw/net/vmxnet3: Fix guest-triggerable assert()
huth Aug 17, 2023
eeee989
qxl: don't assert() if device isn't yet initialized
elmarco Aug 14, 2023
df33ce9
virtio: Drop out of coroutine context in virtio_load()
kevmw Sep 5, 2023
9832a67
arm64: Restore trapless ptimer access
coltonlewis Aug 31, 2023
3d6251f
hw/char/riscv_htif: Fix printing of console characters on big endian …
huth Jul 21, 2023
b9f8329
hw/char/riscv_htif: Fix the console syscall on big endian hosts
huth Jul 21, 2023
987e90c
target/riscv/cpu.c: add zmmul isa string
danielhb Jul 20, 2023
6c24b60
target/riscv: Fix page_check_range use in fault-only-first
romanheros Jul 29, 2023
8ae2012
target/riscv: Fix zfa fleq.d and fltq.d
romanheros Jul 28, 2023
566dac7
hw/intc: Fix upper/lower mtime write calculation
Jul 28, 2023
60a7f5c
hw/intc: Make rtc variable names consistent
Jul 28, 2023
2947da7
linux-user/riscv: Use abi type for target_ucontext
romanheros Aug 11, 2023
b822207
hw/riscv: virt: Fix riscv,pmu DT node path
ConchuOD Jul 27, 2023
1d4fb58
target/riscv: fix satp_mode_finalize() when satp_mode.supported = 0
danielhb Aug 17, 2023
7385e00
target/riscv/pmp.c: respect mseccfg.RLB for pmpaddrX changes
Aug 29, 2023
cae7dc1
target/riscv: Allocate itrigger timers only once
akihikodaki Aug 18, 2023
d4919bb
virtio-gpu/win32: set the destroy function on load
elmarco Sep 6, 2023
8b47922
ui: fix crash when there are no active_console
elmarco Sep 11, 2023
60da830
s390x/ap: fix missing subsystem reset registration
frankjaa Aug 23, 2023
56270e5
meson: Fix targetos match for illumos and Solaris.
jperkin Sep 8, 2023
045fa84
tpm: fix crash when FD >= 1024 and unnecessary errors due to EINTR
elmarco Sep 11, 2023
6bb4a8a
Update version for 8.1.1 release
Sep 21, 2023
ded5ede
hw/ppc: Introduce functions for conversion between timebase and nanos…
npiggin Aug 8, 2023
4bff0a8
host-utils: Add muldiv64_round_up
npiggin Aug 8, 2023
73b7a81
hw/ppc: Round up the decrementer interval when converting to ns
npiggin Aug 8, 2023
0e35c81
hw/ppc: Avoid decrementer rounding errors
npiggin Aug 8, 2023
97fec8f
target/ppc: Sign-extend large decrementer to 64-bits
npiggin Aug 8, 2023
1c2343c
hw/ppc: Always store the decrementer value
npiggin Aug 8, 2023
b6fa8e4
hw/ppc: Reset timebase facilities on machine reset
npiggin Aug 8, 2023
fb9e035
hw/ppc: Read time only once to perform decrementer write
npiggin Aug 8, 2023
f7f97b9
linux-user/hppa: clear the PSW 'N' bit when delivering signals
Sep 16, 2023
fda70be
linux-user/hppa: lock both words of function descriptor
Sep 16, 2023
6970f5b
hw/cxl: Fix CFMW config memory leak
zhijianli88 Sep 4, 2023
f59caec
hw/cxl: Fix out of bound array access
Sep 19, 2023
c2e6a00
file-posix: Clear bs->bl.zoned on error
XanClic Aug 24, 2023
825af96
file-posix: Check bs->bl.zoned for zone info
XanClic Aug 24, 2023
31a4714
file-posix: Fix zone update in I/O error path
XanClic Aug 24, 2023
8ef6104
file-posix: Simplify raw_co_prw's 'out' zone code
XanClic Aug 24, 2023
8a04330
tests/file-io-error: New test
XanClic Aug 24, 2023
cb6ed2f
include/exec: Widen tlb_hit/tlb_hit_page()
Aug 7, 2023
d0cd94e
hw/arm/boot: Set SCR_EL3.FGTEn when booting kernel
Vogtinator Sep 15, 2023
7329cc1
target/arm: Don't skip MTE checks for LDRT/STRT at EL0
pm215 Sep 12, 2023
0215e8e
meson.build: Make keyutils independent from keyring
huth Aug 24, 2023
b9b84b2
accel/tcg: mttcg remove false-negative halted assertion
npiggin Aug 29, 2023
6b7fa3c
hw/scsi/scsi-disk: Disallow block sizes smaller than 512 [CVE-2023-42…
huth Sep 25, 2023
17f3a62
ui/vnc: fix debug output for invalid audio message
bonzini Sep 25, 2023
3b86b92
ui/vnc: fix handling of VNC_FEATURE_XVP
bonzini Sep 25, 2023
0b246f8
migration: Fix race that dest preempt thread close too early
xzpeter Sep 18, 2023
cc3a334
migration: Fix possible race when setting rp_state.error
Sep 18, 2023
f5480c4
migration: Fix possible races when shutting down the return path
Sep 18, 2023
73393af
migration: Fix possible race when shutting down to_dst_file
Sep 18, 2023
d37260b
migration: Remove redundant cleanup of postcopy_qemufile_src
Sep 18, 2023
1ad3fa1
migration: Consolidate return path closing code
Sep 18, 2023
dec7785
migration: Replace the return path retry logic
Sep 18, 2023
4ade907
migration: Move return path cleanup to main migration thread
Sep 18, 2023
d9ec18a
softmmu: Use async_run_on_cpu in tcg_commit
rth7680 Aug 25, 2023
837ca79
accel/tcg: Avoid load of icount_decr if unused
rth7680 Sep 14, 2023
de11111
accel/tcg: Hoist CF_MEMI_ONLY check outside translation loop
rth7680 Sep 14, 2023
a98097d
accel/tcg: Track current value of can_do_io in the TB
rth7680 Sep 14, 2023
6c2e2e4
accel/tcg: Improve setting of can_do_io at start of TB
rth7680 Sep 14, 2023
d6cca99
accel/tcg: Always set CF_LAST_IO with CF_NOIRQ
rth7680 Sep 14, 2023
9fb45b0
accel/tcg: Always require can_do_io
rth7680 Sep 13, 2023
d1b867c
target/tricore: Fix RCPW/RRPW_INSERT insns for width = 0
bkoppelmann Aug 28, 2023
ee7ce8a
optionrom: Remove build-id section
Sep 26, 2023
8194d58
esp: use correct type for esp_dma_enable() in sysbus_esp_gpio_demux()
mcayland Sep 13, 2023
e855a6e
esp: restrict non-DMA transfer length to that of available data
mcayland Sep 13, 2023
f9f1d09
scsi-disk: ensure that FORMAT UNIT commands are terminated
mcayland Sep 13, 2023
6831048
subprojects/berkeley-testfloat-3: Update to fix a problem with compil…
huth Aug 16, 2023
db2d4bc
target/i386: generalize operand size "ph" for use in CVTPS2PD
bonzini Aug 29, 2023
1e58398
target/i386: fix memory operand size for CVTPS2PD
bonzini Aug 29, 2023
ab63145
win32: avoid discarding the exception handler
elmarco Sep 25, 2023
7771e35
hw/display/ramfb: plug slight guest-triggerable leak on mode setting
Sep 19, 2023
19159a7
chardev/char-pty: Avoid losing bytes when the other side just (re-)co…
huth Aug 16, 2023
2990ba5
linux-user/hppa: Fix struct target_sigcontext layout
rth7680 Sep 30, 2023
809d599
vdpa net: zero vhost_vdpa iova_tree pointer at cleanup
eugpermar Sep 13, 2023
197cc86
vdpa net: fix error message setting virtio status
eugpermar Sep 15, 2023
e6d9dd1
vdpa net: stop probing if cannot set features
eugpermar Sep 15, 2023
fe3afc0
vdpa net: follow VirtIO initialization properly at cvq isolation probing
eugpermar Sep 15, 2023
2adbc3b
amd_iommu: Fix APIC address check
akihikodaki Sep 21, 2023
0f1d63d
vfio/display: Fix missing update to set backing fields
awilliam Aug 16, 2023
d8b9e0c
util/log: re-allow switching away from stderr log file
foxmox Oct 4, 2023
b617071
migration/qmp: Fix crash on setting tls-authz with null
xzpeter Sep 5, 2023
5dddba9
hw/audio/es1370: reset current sample counter
Sep 17, 2023
2e42ba0
roms: use PYTHON to invoke python
olafhering Oct 2, 2023
a8c0d82
disas/riscv: Fix the typo of inverted order of pmpaddr13 and pmpaddr14
gagachang Sep 7, 2023
cc33ee4
target/riscv: Fix vfwmaccbf16.vf
rnax Oct 5, 2023
78385bc
Update version for 8.1.2 release
Oct 16, 2023
0b3bd15
Add tracewrap
thestr4ng3r Jan 30, 2022
bc08125
Ask for the absolute path to bap-frames.
Rot127 Jul 29, 2023
d72c270
Add simple build CI workflow.
Rot127 Sep 12, 2023
ec9b1b2
Add missing meson_option_add and a summary info
Rot127 Sep 12, 2023
cb388d7
Update build.yaml
ivg Oct 26, 2023
67f77c8
Update CI build.yaml
Rot127 Nov 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build target user

on: [pull_request, workflow_dispatch]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Copy source.list file to include deb-src
run: |
sudo cp /etc/apt/sources.list /etc/apt/sources.list.d/tmp.list
sudo sed -i "s/# deb-src/deb-src/g" /etc/apt/sources.list.d/tmp.list
- name: Install deps
run: |
sudo apt-get update
sudo apt-get --no-install-recommends -y build-dep qemu
sudo apt-get install -y autoconf libtool protobuf-c-compiler
pip3 install --user ninja
- name: Install OCaml
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.14.x
dune-cache: true
opam-disable-sandboxing: true
- name: Install piqi
run: |
opam install piqi
- name: Clone qemu and bap-frames
run: |
git clone --depth 1 http://github.com/BinaryAnalysisPlatform/bap-frames.git
git clone --depth 1 http://github.com/BinaryAnalysisPlatform/qemu.git
- name: Build without tracewrap
run: |
cd qemu
./configure --prefix=$HOME --target-list=arm-linux-user
ninja -C build
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Overview

Qemu tracer - a tracer based on [qemu](https://github.com/qemu/qemu)
project. It executes a binary executable and saves trace data using
[Protocol Buffer](https://developers.google.com/protocol-buffers/)
format. The contents of the trace data is defined in
[bap-traces](https://github.com/BinaryAnalysisPlatform/bap-traces)
project.

# Installing released binaries

If you don't want to mess with the source and building, then you can just
dowload a tarball with prebuilt binaries. Look at the latest release and
it might happen, that we have built binaries for your linux distribution,
if it is not the case, then create an issue, and we will build it for you.

Let's pretend, that you're using Ubuntu Trusty, and install it. First
download it with your favorite downloader:

```
wget https://github.com/BinaryAnalysisPlatform/qemu/releases/download/v2.0.0-tracewrap-2.0.0-rc1/qemu-tracewrap-ubuntu-14.04.4-LTS.tgz
```

Install it in the specified prefix with a command like `tar -C <prefix> -xf qemu-tracewrap-ubuntu-14.04.4-LTS.tgz`, e.g.,
to install in your home directory:
```
tar -C $HOME -xf qemu-tracewrap-ubuntu-14.04.4-LTS.tgz
```



# Build

## Preparation

Note: the instructions assume that you're using Ubuntu, but it
may work on other systems, that uses apt-get.

Before building the qemu-tracewrap, you need to install the following packages:
* qemu build dependencies
* autoconf, libtool, protobuf-c-compiler
* [piqi library](http://piqi.org/doc/ocaml)

To install qemu build dependencies, use the following command

```bash
$ sudo apt-get --no-install-recommends -y build-dep qemu
```

To install autoconf, libtool, protobuf-c-compiler, use the
following command

```bash
$ sudo apt-get install autoconf libtool protobuf-c-compiler
```

To install [piqi library](http://piqi.org/doc/ocaml) with
[opam](https://opam.ocaml.org/doc/Install.html), use the following command
```bash
$ opam install piqi
```

## Building

Download [bap-frames](https://github.com/BinaryAnalysisPlatform/bap-frames) with
following command

```bash
$ git clone https://github.com/BinaryAnalysisPlatform/bap-frames.git
```

Download qemu tracer with following command

```bash
$ git clone git@github.com:BinaryAnalysisPlatform/qemu.git
```

Change folder to qemu and build tracer:
```bash
$ cd qemu
$ ./configure --prefix=$HOME --with-tracewrap=<absolute-path-to>/bap-frames --target-list=<ARCH>-linux-user
$ ninja -C build
$ ninja -C build install
```

# Usage

To run executable `exec` compiled for `arch`, use `qemu-arch exec` command, e.g.,
`qemu-x86_64 /bin/ls`. It will dump the trace into `ls.frames` file. You can configure
the filename with `-tracefile` option, e.g., `qemu-arm -tracefile arm.ls.frames ls`


Hints: use option -L to set the elf interpreter prefix to 'path'. Use
[fetchlibs.sh](https://raw.githubusercontent.com/BinaryAnalysisPlatform/bap-frames/master/test/fetchlibs.sh)
to download arm and x86 libraries.

# Notes
Only ARM, X86, X86-64, MIPS targets are supported in this branch.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.1.0
8.1.2
4 changes: 3 additions & 1 deletion accel/kvm/kvm-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ static int kvm_init(MachineState *ms)
KVMState *s;
const KVMCapabilityInfo *missing_cap;
int ret;
int type = 0;
int type;
uint64_t dirty_log_manual_caps;

qemu_mutex_init(&kml_slots_lock);
Expand Down Expand Up @@ -2523,6 +2523,8 @@ static int kvm_init(MachineState *ms)
type = mc->kvm_type(ms, kvm_type);
} else if (mc->kvm_type) {
type = mc->kvm_type(ms, NULL);
} else {
type = kvm_arch_get_default_type(ms);
}

do {
Expand Down
30 changes: 0 additions & 30 deletions accel/tcg/cpu-exec-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,6 @@ void cpu_loop_exit_noexc(CPUState *cpu)
cpu_loop_exit(cpu);
}

#if defined(CONFIG_SOFTMMU)
void cpu_reloading_memory_map(void)
{
if (qemu_in_vcpu_thread() && current_cpu->running) {
/* The guest can in theory prolong the RCU critical section as long
* as it feels like. The major problem with this is that because it
* can do multiple reconfigurations of the memory map within the
* critical section, we could potentially accumulate an unbounded
* collection of memory data structures awaiting reclamation.
*
* Because the only thing we're currently protecting with RCU is the
* memory data structures, it's sufficient to break the critical section
* in this callback, which we know will get called every time the
* memory map is rearranged.
*
* (If we add anything else in the system that uses RCU to protect
* its data structures, we will need to implement some other mechanism
* to force TCG CPUs to exit the critical section, at which point this
* part of this callback might become unnecessary.)
*
* This pair matches cpu_exec's rcu_read_lock()/rcu_read_unlock(), which
* only protects cpu->as->dispatch. Since we know our caller is about
* to reload it, it's safe to split the critical section.
*/
rcu_read_unlock();
rcu_read_lock();
}
}
#endif

void cpu_loop_exit(CPUState *cpu)
{
/* Undo the setting in cpu_tb_exec. */
Expand Down
4 changes: 3 additions & 1 deletion accel/tcg/cpu-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
&& cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0) {
/* Execute just one insn to trigger exception pending in the log */
cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT)
| CF_NOIRQ | 1;
| CF_LAST_IO | CF_NOIRQ | 1;
}
#endif
return false;
Expand Down Expand Up @@ -1032,10 +1032,12 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
last_tb = NULL;
}
#endif
#ifndef HAS_TRACEWRAP
/* See if we can patch the calling TB. */
if (last_tb) {
tb_add_jump(last_tb, tb_exit, tb);
}
#endif

cpu_loop_exec_tb(cpu, tb, pc, &last_tb, &tb_exit);

Expand Down
6 changes: 4 additions & 2 deletions accel/tcg/tb-maint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,8 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc)
if (current_tb_modified) {
/* Force execution of one insn next time. */
CPUState *cpu = current_cpu;
cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
cpu->cflags_next_tb =
1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
return true;
}
return false;
Expand Down Expand Up @@ -1153,7 +1154,8 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,
if (current_tb_modified) {
page_collection_unlock(pages);
/* Force execution of one insn next time. */
current_cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
current_cpu->cflags_next_tb =
1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
mmap_unlock();
cpu_loop_exit_noexc(current_cpu);
}
Expand Down
9 changes: 2 additions & 7 deletions accel/tcg/tcg-accel-ops-mttcg.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,9 @@ static void *mttcg_cpu_thread_fn(void *arg)
break;
case EXCP_HALTED:
/*
* during start-up the vCPU is reset and the thread is
* kicked several times. If we don't ensure we go back
* to sleep in the halted state we won't cleanly
* start-up when the vCPU is enabled.
*
* cpu->halted should ensure we sleep in wait_io_event
* Usually cpu->halted is set, but may have already been
* reset by another thread by the time we arrive here.
*/
g_assert(cpu->halted);
break;
case EXCP_ATOMIC:
qemu_mutex_unlock_iothread();
Expand Down
72 changes: 34 additions & 38 deletions accel/tcg/translator.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,19 @@
#include "tcg/tcg-op-common.h"
#include "internal.h"

static void gen_io_start(void)
static void set_can_do_io(DisasContextBase *db, bool val)
{
tcg_gen_st_i32(tcg_constant_i32(1), cpu_env,
offsetof(ArchCPU, parent_obj.can_do_io) -
offsetof(ArchCPU, env));
if (db->saved_can_do_io != val) {
db->saved_can_do_io = val;
tcg_gen_st_i32(tcg_constant_i32(val), cpu_env,
offsetof(ArchCPU, parent_obj.can_do_io) -
offsetof(ArchCPU, env));
}
}

bool translator_io_start(DisasContextBase *db)
{
uint32_t cflags = tb_cflags(db->tb);

if (!(cflags & CF_USE_ICOUNT)) {
return false;
}
if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) {
/* Already started in translator_loop. */
return true;
}

gen_io_start();
set_can_do_io(db, true);

/*
* Ensure that this instruction will be the last in the TB.
Expand All @@ -47,14 +40,17 @@ bool translator_io_start(DisasContextBase *db)
return true;
}

static TCGOp *gen_tb_start(uint32_t cflags)
static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
{
TCGv_i32 count = tcg_temp_new_i32();
TCGv_i32 count = NULL;
TCGOp *icount_start_insn = NULL;

tcg_gen_ld_i32(count, cpu_env,
offsetof(ArchCPU, neg.icount_decr.u32) -
offsetof(ArchCPU, env));
if ((cflags & CF_USE_ICOUNT) || !(cflags & CF_NOIRQ)) {
count = tcg_temp_new_i32();
tcg_gen_ld_i32(count, cpu_env,
offsetof(ArchCPU, neg.icount_decr.u32) -
offsetof(ArchCPU, env));
}

if (cflags & CF_USE_ICOUNT) {
/*
Expand Down Expand Up @@ -84,18 +80,15 @@ static TCGOp *gen_tb_start(uint32_t cflags)
tcg_gen_st16_i32(count, cpu_env,
offsetof(ArchCPU, neg.icount_decr.u16.low) -
offsetof(ArchCPU, env));
/*
* cpu->can_do_io is cleared automatically here at the beginning of
* each translation block. The cost is minimal and only paid for
* -icount, plus it would be very easy to forget doing it in the
* translator. Doing it here means we don't need a gen_io_end() to
* go with gen_io_start().
*/
tcg_gen_st_i32(tcg_constant_i32(0), cpu_env,
offsetof(ArchCPU, parent_obj.can_do_io) -
offsetof(ArchCPU, env));
}

/*
* cpu->can_do_io is set automatically here at the beginning of
* each translation block. The cost is minimal, plus it would be
* very easy to forget doing it in the translator.
*/
set_can_do_io(db, db->max_insns == 1 && (cflags & CF_LAST_IO));

return icount_start_insn;
}

Expand Down Expand Up @@ -144,18 +137,25 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
db->num_insns = 0;
db->max_insns = *max_insns;
db->singlestep_enabled = cflags & CF_SINGLE_STEP;
db->saved_can_do_io = -1;
db->host_addr[0] = host_pc;
db->host_addr[1] = NULL;

ops->init_disas_context(db, cpu);
tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */

/* Start translating. */
icount_start_insn = gen_tb_start(cflags);
icount_start_insn = gen_tb_start(db, cflags);
ops->tb_start(db, cpu);
tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */

plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY);
if (cflags & CF_MEMI_ONLY) {
/* We should only see CF_MEMI_ONLY for io_recompile. */
assert(cflags & CF_LAST_IO);
plugin_enabled = plugin_gen_tb_start(cpu, db, true);
} else {
plugin_enabled = plugin_gen_tb_start(cpu, db, false);
}

while (true) {
*max_insns = ++db->num_insns;
Expand All @@ -172,13 +172,9 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
the next instruction. */
if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) {
/* Accept I/O on the last instruction. */
gen_io_start();
ops->translate_insn(db, cpu);
} else {
/* we should only see CF_MEMI_ONLY for io_recompile */
tcg_debug_assert(!(cflags & CF_MEMI_ONLY));
ops->translate_insn(db, cpu);
set_can_do_io(db, true);
}
ops->translate_insn(db, cpu);

/*
* We can't instrument after instructions that change control
Expand Down
Loading