Commit Graph

926 Commits

Author SHA1 Message Date
mio
334e83efd7 fix static variables used in m68k 2025-04-13 11:49:05 +08:00
Amaan Qureshi
aa86641e16 fix(m68k): correct SR register read (#2161)
The SR register in the `CPUM68KState` struct does not contain the value
of the lower 5 flags. To compute them, we must OR the CCR values with
the SR register to get the true SR value.
2025-04-13 11:03:08 +08:00
mio
b8c9d777f4 Fix decleration 2025-04-13 01:15:45 +08:00
mio
7795248730 Fix PPC symbol clash 2025-04-13 01:13:39 +08:00
mio
bd5a8c5146 Squashed commit of the following:
commit 520c6647c32f02d83083d969d416154aa95e922c
Merge: 6bb29b12 b999f507
Author: mio <mio@lazym.io>
Date:   Sun Apr 13 00:14:23 2025 +0800

    merge dev

commit 6bb29b12f1d9f452365cc9cb5bc2d65ef376af30
Author: mio <mio@lazym.io>
Date:   Sun Apr 13 00:13:12 2025 +0800

    enable test

commit bcb8b363ef12ac295cf4fe4f1645416e5f0ea6ae
Author: mio <mio@lazym.io>
Date:   Sun Apr 13 00:13:06 2025 +0800

    also logging

commit 5972fc156b7379d09582c745d6d597e07555f2f4
Author: mio <mio@lazym.io>
Date:   Sun Apr 13 00:12:58 2025 +0800

    no unlimited translation

commit 7d600feebf9055505918e50d0af8b529a3eba542
Author: mio <mio@lazym.io>
Date:   Sun Apr 13 00:12:47 2025 +0800

    Ignore bindings.rs

commit dde4d50f2c7713156ac3bc284287480e4d92005f
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sun Apr 6 03:26:22 2025 -0400

    alias `uc_mips_reg` to `UC_MIPS_REG`

commit 04234ae01ba7c82d9717eaae64cdda289ce3b832
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sun Apr 6 01:13:00 2025 -0400

    remove bindings.rs

commit edec1300cd7c2d8ef4babbd51f6bcba2e126bdd7
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Apr 5 14:29:40 2025 -0400

    address review

commit feb157b28b6c262c5dc3d810ec54de55a25bcd6e
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 22:40:53 2025 -0400

    ci(rust): rework workflow

    The notable changes are migrating to
    `actions-rust-lang/setup-rust-toolchain` for setting up Rust as it's
    maintained, and using `katyo/publish-crates` for publishing crates in a
    workspace

commit c1c7a8f8ed841b6ec5b4abe57013a1c2c9748c60
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 22:40:06 2025 -0400

    build(rust): set `rust-version` to 1.85

commit 8df938c9f8b478160213707674157103b0893caf
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 21:53:21 2025 -0400

    fix(rust): correct unsound pointer cast

    The size of `T` is not guaranteed to be the size of `i32` - all we know
    is that `T` is `Into<i32>`, so we should first copy them over into an
    `i32` array

commit 3059b2583a60aa0cac9278afc945ed87f7ddb65e
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 20:13:26 2025 -0400

    docs(rust): update readme

commit 7db69a888e58a4bda20083e4e0771d26a327ad13
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:58:30 2025 -0400

    feat(rust): add comprehensive tests

    These tests are copied over from the C tests

commit 78f2207f0e0481aef4de6d5908f8dc699a39a8d5
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:57:27 2025 -0400

    feat(rust): add tcg hook

commit 46e53328531ec3279dadbf18c16b493432227b31
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:56:55 2025 -0400

    feat(rust): add a hook for arm64 sys instructions

commit d1b58ee8282bf1eeeefbf68c87c2cf7c50c90320
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:56:35 2025 -0400

    feat(rust): add the ability to read the arm coprocessor register

commit d304da18b9e6741042b2a70657437be8f39f5c7c
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:55:29 2025 -0400

    feat(rust): add missing `Context` methods

commit 0dd87833081ac9db1feaf5bae8c839a7a2ae4947
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:44:51 2025 -0400

    refactor(rust): remove unnecessary code

    `unicorn-engine-sys` will provide the necessary constants & types

commit da3d2fa7c3ecd3ae8fdb6672b6c5ea23da4570ff
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:43:57 2025 -0400

    feat(rust): add a workspace `Cargo.toml`, and use `unicorn-engine-sys`

commit b27a2a93e4ac43aa2079e936df4dd30a1f8f329a
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:38:06 2025 -0400

    feat(rust): introduce `unicorn-engine-sys` crate

    This crate contains generated Rust bindings to the C library via
    bindgen. It is independent from the main `unicorn-engine` bindings,
    which will leverage this

commit bcec87a3f6e316e328683c303ccfa89e530a6c56
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:31:24 2025 -0400

    test(m68k): actually assert an expectation

    This test did not actually test for anything before

commit bc7e65ca96164496eb2e250b1f296a33a8aa58ee
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:31:09 2025 -0400

    style(test): use bitflag shorthands

commit 0ab4b7fefb3ca17b0b5977d7b204291c5de184ad
Author: Amaan Qureshi <amaanq12@gmail.com>
Date:   Sat Mar 29 13:22:13 2025 -0400

    fix(mips): lowercase enum name `uc_mips_reg`

    This aligns with other architectures

Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
2025-04-13 00:17:55 +08:00
mio
b999f507b9 fix load_helper & store_helper for PC sync 2025-04-12 23:37:20 +08:00
mio
2d04b2a71d more PC sync for HOOK_INSN 2025-04-12 23:24:49 +08:00
mio
83ad137ac2 Sync HOOK_INSN hooks 2025-04-12 23:22:04 +08:00
mio
4a13bc7cb8 Sync pc before memory hooks
This ensures correct PC for any arch
2025-04-12 22:08:44 +08:00
Amaan Qureshi
3a7bde03b8 feat(arm): add an ESR register (#2155)
This allows users to read/write from the ARM syndrome value like in
AArch64.
2025-04-12 21:46:37 +08:00
mio
7f48b1dd4a No longer used hacked liveness_pass_1
This hack was introduced in issue#287 which later becomes endless maintainance pain.

=====

Our previous check_exit_request use `brcond` in the middle of a TranslationBlock which

breaks the assumptions and thus a hack to liveness_pass_1 is used for _all_ brcond instructions

which causes issues for MIPS and many other scenarios.

=====

This patch also resolves PC not sync-ed when no memory hooks are installed, finally. Now

Unicorn will always have correct PC no matter what happens.
2025-04-12 21:38:14 +08:00
ExhoAR22
bc73cb232d Fix physical address truncation on 32-bit systems with addressing extensions (#2139)
* use hwaddr for paddrs

* Fix the truncation for memory hooks as well

* Add LPAE regression test


Co-authored-by: Takacs, Philipp <philipp.takacs@iosb.fraunhofer.de>
2025-04-01 10:53:18 +08:00
mio
0bb1bbd93c Initialize delay_slot_flag correctly 2025-03-18 21:20:54 +08:00
mio
3870cdcaf3 Format code 2025-03-10 11:31:53 +08:00
mio
d3674f84b4 implement m68k cr registers 2025-03-10 11:31:22 +08:00
PhilippTakacs
65ed715081 Snapshot use after free (#2125)
* memory snapshots fix use after free on flatview copy

When restoring a snapshot with memory the flatview must be restored
before the memory reagions are filtered. Because the
AddressSpaceDispatcher also has pointer to the MemoryRegions and on copy
they need to be cleared. The memory_filter_subregions function frees
MemoryRegions which are not used at the time of the snapshot.

* fix some memleaks in tests

These tests has forgott to call uc_close(uc), which lead to memory
leaks. Found by the LeakSanitizer.

* memory snapshots correct clean up container memory regions

* Fix further stackoverflow in tests

---------

Co-authored-by: mio <mio@lazym.io>
2025-03-06 23:23:02 +08:00
mio
986f67c70a Correct PRI 2025-03-05 00:32:10 +08:00
mio
9da2fec784 Fix mips64 crash on x86 targets 2025-03-04 23:36:56 +08:00
mio
2128e01efc Init tcg region buffer 2025-02-25 13:52:26 +08:00
OBarronCS
76d97f8926 Support MIPS64 - write correct PC register width on uc_emu_start (#2111)
* Support mips64 - write correct pc register width on uc_emu_start

* Convert to UC_MODE_MIPS64

* Correctly select MIPS64 CPU model

* Simple 64-bit test - check it doesn't crash

* lint

* Comment

* Comment

* Add offset when indexing cpu model, makes tests work on older python

* Move test

* add PC check to test

* Fix test - add python version check

* Use RegressTest method for assert
2025-02-21 21:39:11 +08:00
mio
56ba3476e5 Fix long-standing mips delay slot issue 2025-02-19 17:39:24 +08:00
mio
e7ad2fda91 Further fix MIPS delay slot 2025-02-18 23:34:09 +08:00
mio
1cb8952b14 Default x86 CPU model to UC_CPU_X86_HASWELL
Rationale: Previouly, Unicorn uses several hacks to pretend it supports
floating point instructions while not properly setting up something
like CPU features. Therefore, once related registers like CR4 is reset,
the hacks stop working and UC_ERR_INSN_INVALID is thrown. Setting the default
model to a CPu that has basical floating point support should have the
minimal break changes.
2025-02-18 12:13:24 +08:00
mio
4d173ea376 Revert FPU related changes 2025-02-18 11:13:22 +08:00
mio
0f6ec4ca9d Also initialize CR4 for UC_MODE_32 2025-02-18 10:47:35 +08:00
mio
1dae6bb774 Correctly implement CR4 2025-02-18 10:43:52 +08:00
mio
c97449869d Format code 2025-02-17 20:17:10 +08:00
mio
0c6f7c60d5 Implement mips floating point related registers 2025-02-17 20:16:36 +08:00
Disconnect3d
d03c0922e6 Fix #2103: qemu/target/ppc/mem_helper.c remove redundant return statements (#2104) 2025-02-15 01:04:30 +08:00
Amaan Qureshi
6b9c1c851c fix(arm): correct write to ARM coprocessor (#2099)
This code was commented out since 2021, but by default, the error
codewas initialized to `UC_REG_OK`, so there was no error returned
untila result, any write to `UC_ARM_REG_C1_C0_2` returned an error.
2025-02-13 19:25:26 +08:00
mio
791557e404 CI(full),CI(release): Should use if instead of ifdef 2025-02-11 17:44:24 +08:00
mio
5981f10c5d CI(full),CI(release): Fix symbol clash (again) 2025-02-11 16:33:40 +08:00
mio
d437090bbc CI(full),CI(release): Fix symbol clash 2025-02-11 16:28:45 +08:00
mio
b4eb933ec8 CI(full),CI(release): Do not refer to ATOMIC128 symbols if not available 2025-02-11 16:24:49 +08:00
mio
381850356f CI(full),CI(release): More PPC64 atomic fixes 2025-02-11 10:18:01 +08:00
mio
ad33384cd2 Unsigned extension 2025-02-10 21:49:38 +08:00
mio
ca3912d9f7 Fix undefined behavior converting TCGv_i32 to TCGv_i64 2025-02-10 21:45:34 +08:00
mio
c915d13cce Fix pc issue of tcg opcode hooks 2025-02-10 21:35:17 +08:00
mio
77a841e53d Fix signature 2025-02-10 21:29:03 +08:00
mio
2619b12cf0 set pc_start on disasm 2025-02-10 21:28:23 +08:00
mio
904efc16c0 Should use tcg_ctx->pc_start as pc 2025-02-10 21:20:39 +08:00
mio
a903fa182b Avoid null ptr deref when writing to arm context pc register 2025-02-10 15:58:28 +08:00
dotcirill
dc1f7a88d5 Uc hook tcg improve (#2011)
* Add handling UC_TCG_OP_FLAG_CMP for ARM

Implementation is not well-tested and complete

* Hook ARM32 CMP and CMN for cmplog
2025-02-10 15:01:21 +08:00
Shivam7-1
ada8091ccc Fix heap buffer overflow in op_cksm function (#2096)
* Fix heap-buffer-overflow in op_cksm function

* Update header
2025-02-10 14:57:08 +08:00
xndcn
1ba25def8e Fix UC_HOOK_MEM on arm32 (#2091) 2025-01-26 13:28:24 +08:00
ZakDanger
d7c0497ee3 Added start in mips16 mode support, and unit test for it - on dev branch (#2089)
Co-authored-by: ZakDanger <ZakDanger@users.noreply.github.com>
2025-01-19 17:35:40 +08:00
0c512f91a1 Fix #1643
This adds an extra op to translator to allow the block hook sync pc in the very begining
2025-01-18 15:07:22 +08:00
Z. Liu
a78d690da5 configure: add <sys/timex.h> for clock_adjtime on musl (#2085)
for glibc, if _GNU_SOURCE is defined, <time.h> will include <sys/timex.h>
but not for musl, so add "#include <sys/timex.h>"

although `man clock_adjtime` said "#include <sys/timex.h>", but it won't
work for glibc w/o "#include <time.h>", I don't known why yet.

PS it seems clock_adjtime is used nowhere?

Signed-off-by: Z. Liu <zhixu.liu@gmail.com>
2025-01-14 08:47:54 +08:00
Glenn Baker
8442eb6feb qemu/tcg: fix UC_HOOK_MEM_READ on aarch64. (#2028)
* qemu/tcg: fix UC_HOOK_MEM_READ on aarch64.

Directly jump into the slow path when there is any hookmem enabled. This
fixes #1908.

Signed-off-by: Glenn Baker <glenn.baker@gmx.com>

* qemu/tcg: fix UC_HOOK_MEM_READ on ppc64.

Directly jump into the slow path when there is any hookmem enabled.

Signed-off-by: Glenn Baker <glenn.baker@gmx.com>

* qemu/tcg: check for UC_HOOK_MEM_READ_AFTER.

Use has_hookmem() helper to determine wether "slow-path" TLB read is
needed. Add this helper to x86 architecture as well so that to check for
all hookmem.

Signed-off-by: Glenn Baker <glenn.baker@gmx.com>

* qemu/tcg: factor out has_hookmem().

It's the same implementation for all architectures, so factor out
has_hookmem() into tcg_uc_has_hookmem().

Signed-off-by: Glenn Baker <glenn.baker@gmx.com>

---------

Signed-off-by: Glenn Baker <glenn.baker@gmx.com>
2025-01-04 18:48:53 +08:00
mio
2c688bae73 Remove the outdated hack to zero all code gen buffer
This shall also improve performance

Fix #2001
2025-01-04 17:05:34 +08:00