[PATCH 00/12] target/loongarch: Move CSR registers to struct CPUSysState

Bibo Mao posted 12 patches 4 days, 10 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260526065023.1639371-1-maobibo@loongson.cn
Maintainers: Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>
hw/intc/loongarch_dintc.c                     |   4 +-
target/loongarch/arch_dump.c                  |   5 +-
target/loongarch/cpu-mmu.h                    |   4 +-
target/loongarch/cpu.c                        | 120 ++++-----
target/loongarch/cpu.h                        |  49 ++--
target/loongarch/cpu_helper.c                 |  41 ++--
target/loongarch/csr.c                        |  10 +-
target/loongarch/csr.h                        |   5 +
target/loongarch/gdbstub.c                    |   3 +-
target/loongarch/kvm/kvm.c                    | 228 +++++++++---------
target/loongarch/machine.c                    | 116 ++++-----
target/loongarch/tcg/constant_timer.c         |  10 +-
target/loongarch/tcg/csr_helper.c             |  55 +++--
.../tcg/insn_trans/trans_extra.c.inc          |  11 +-
.../tcg/insn_trans/trans_privileged.c.inc     |  16 +-
target/loongarch/tcg/op_helper.c              |  45 ++--
target/loongarch/tcg/tcg_cpu.c                | 107 ++++----
target/loongarch/tcg/tlb_helper.c             | 137 ++++++-----
18 files changed, 531 insertions(+), 435 deletions(-)
[PATCH 00/12] target/loongarch: Move CSR registers to struct CPUSysState
Posted by Bibo Mao 4 days, 10 hours ago
Here new structure CPUSysState is added in CPULoongArchState, CSR
registers are move in CPUSysState. In later with LVZ supported, there will
be two copied of CSR registers, so it is simply to add CPUSysState array.

Also new field curState is added which points to CPUSysState at
beginning, and it can be changed during VM exit/enter entry. There is no
function change, all is code movement or variable rename.

Bibo Mao (12):
  target/loongarch: Add new field curState in CPULoongArchState
  target/loongarch: Use curState in cpu.c when accessing CSR registers
  target/loongarch: Use curState in cpu_helper.c when accessing CSR
    registers
  target/loongarch: Use curState in file arch_dump.c when accessing CSR
    registers
  target/loongarch: Use curState in kvm.c when accessing CSR registers
  target/loongarch: Use curState in tlb_helper.c when accessing CSR
    registers
  target/loongarch: Use curState in tcg_cpu.c when accessing CSR
    registers
  target/loongarch: Use curState in csr_helper.c when accessing CSR
    registers
  target/loongarch: Use curState in op_helper.c when accessing CSR
    registers
  target/loongarch: Add default CSRFL_BASIC info with flags field
  target/loongarch: Add wrapper function get_csr_offset()
  target/loongarch: Add new structure CPUSysState

 hw/intc/loongarch_dintc.c                     |   4 +-
 target/loongarch/arch_dump.c                  |   5 +-
 target/loongarch/cpu-mmu.h                    |   4 +-
 target/loongarch/cpu.c                        | 120 ++++-----
 target/loongarch/cpu.h                        |  49 ++--
 target/loongarch/cpu_helper.c                 |  41 ++--
 target/loongarch/csr.c                        |  10 +-
 target/loongarch/csr.h                        |   5 +
 target/loongarch/gdbstub.c                    |   3 +-
 target/loongarch/kvm/kvm.c                    | 228 +++++++++---------
 target/loongarch/machine.c                    | 116 ++++-----
 target/loongarch/tcg/constant_timer.c         |  10 +-
 target/loongarch/tcg/csr_helper.c             |  55 +++--
 .../tcg/insn_trans/trans_extra.c.inc          |  11 +-
 .../tcg/insn_trans/trans_privileged.c.inc     |  16 +-
 target/loongarch/tcg/op_helper.c              |  45 ++--
 target/loongarch/tcg/tcg_cpu.c                | 107 ++++----
 target/loongarch/tcg/tlb_helper.c             | 137 ++++++-----
 18 files changed, 531 insertions(+), 435 deletions(-)


base-commit: cbf877d67a812be17a9ce404a589e1bdf722c1f6
-- 
2.39.3
Re: [PATCH 00/12] target/loongarch: Move CSR registers to struct CPUSysState
Posted by Philippe Mathieu-Daudé 4 days, 7 hours ago
On 26/5/26 08:50, Bibo Mao wrote:
> Here new structure CPUSysState is added in CPULoongArchState, CSR
> registers are move in CPUSysState. In later with LVZ supported, there will
> be two copied of CSR registers, so it is simply to add CPUSysState array.
> 
> Also new field curState is added which points to CPUSysState at
> beginning, and it can be changed during VM exit/enter entry. There is no
> function change, all is code movement or variable rename.

Isn't curState misleading? What about:

-    CPUSysState *cur = get_current_state(env);
+    CSRState *csr = env_csr(env);
Re: [PATCH 00/12] target/loongarch: Move CSR registers to struct CPUSysState
Posted by Bibo Mao 4 days, 7 hours ago

On 2026/5/26 下午5:11, Philippe Mathieu-Daudé wrote:
> On 26/5/26 08:50, Bibo Mao wrote:
>> Here new structure CPUSysState is added in CPULoongArchState, CSR
>> registers are move in CPUSysState. In later with LVZ supported, there 
>> will
>> be two copied of CSR registers, so it is simply to add CPUSysState array.
>>
>> Also new field curState is added which points to CPUSysState at
>> beginning, and it can be changed during VM exit/enter entry. There is no
>> function change, all is code movement or variable rename.
> 
> Isn't curState misleading? What about:
> 
> -    CPUSysState *cur = get_current_state(env);
> +    CSRState *csr = env_csr(env);

get_current_state() actually is misleading. In future "QEMUTimer timer" 
will be added in structure CPUSysState(). It is not only CSR registers. 
How about something like this which is copied for yours :)
   -    CPUSysState *cur = get_current_state(env);
   +    SysState *sys = env_sys(env);

Regards
Bibo Mao


Re: [PATCH 00/12] target/loongarch: Move CSR registers to struct CPUSysState
Posted by Philippe Mathieu-Daudé 4 days, 7 hours ago
On 26/5/26 11:35, Bibo Mao wrote:
> 
> 
> On 2026/5/26 下午5:11, Philippe Mathieu-Daudé wrote:
>> On 26/5/26 08:50, Bibo Mao wrote:
>>> Here new structure CPUSysState is added in CPULoongArchState, CSR
>>> registers are move in CPUSysState. In later with LVZ supported, there 
>>> will
>>> be two copied of CSR registers, so it is simply to add CPUSysState 
>>> array.
>>>
>>> Also new field curState is added which points to CPUSysState at
>>> beginning, and it can be changed during VM exit/enter entry. There is no
>>> function change, all is code movement or variable rename.
>>
>> Isn't curState misleading? What about:
>>
>> -    CPUSysState *cur = get_current_state(env);
>> +    CSRState *csr = env_csr(env);
> 
> get_current_state() actually is misleading. In future "QEMUTimer timer" 
> will be added in structure CPUSysState(). It is not only CSR registers. 
> How about something like this which is copied for yours :)
>    -    CPUSysState *cur = get_current_state(env);
>    +    SysState *sys = env_sys(env);

LGTM!


Re: [PATCH 00/12] target/loongarch: Move CSR registers to struct CPUSysState
Posted by gaosong 4 days, 9 hours ago
在 2026/5/26 下午2:50, Bibo Mao 写道:
> Here new structure CPUSysState is added in CPULoongArchState, CSR
> registers are move in CPUSysState. In later with LVZ supported, there will
> be two copied of CSR registers, so it is simply to add CPUSysState array.
>
> Also new field curState is added which points to CPUSysState at
> beginning, and it can be changed during VM exit/enter entry. There is no
> function change, all is code movement or variable rename.
>
> Bibo Mao (12):
>    target/loongarch: Add new field curState in CPULoongArchState
>    target/loongarch: Use curState in cpu.c when accessing CSR registers
>    target/loongarch: Use curState in cpu_helper.c when accessing CSR
>      registers
>    target/loongarch: Use curState in file arch_dump.c when accessing CSR
>      registers
>    target/loongarch: Use curState in kvm.c when accessing CSR registers
>    target/loongarch: Use curState in tlb_helper.c when accessing CSR
>      registers
>    target/loongarch: Use curState in tcg_cpu.c when accessing CSR
>      registers
>    target/loongarch: Use curState in csr_helper.c when accessing CSR
>      registers
>    target/loongarch: Use curState in op_helper.c when accessing CSR
>      registers
>    target/loongarch: Add default CSRFL_BASIC info with flags field
>    target/loongarch: Add wrapper function get_csr_offset()
>    target/loongarch: Add new structure CPUSysState
>
>   hw/intc/loongarch_dintc.c                     |   4 +-
>   target/loongarch/arch_dump.c                  |   5 +-
>   target/loongarch/cpu-mmu.h                    |   4 +-
>   target/loongarch/cpu.c                        | 120 ++++-----
>   target/loongarch/cpu.h                        |  49 ++--
>   target/loongarch/cpu_helper.c                 |  41 ++--
>   target/loongarch/csr.c                        |  10 +-
>   target/loongarch/csr.h                        |   5 +
>   target/loongarch/gdbstub.c                    |   3 +-
>   target/loongarch/kvm/kvm.c                    | 228 +++++++++---------
>   target/loongarch/machine.c                    | 116 ++++-----
>   target/loongarch/tcg/constant_timer.c         |  10 +-
>   target/loongarch/tcg/csr_helper.c             |  55 +++--
>   .../tcg/insn_trans/trans_extra.c.inc          |  11 +-
>   .../tcg/insn_trans/trans_privileged.c.inc     |  16 +-
>   target/loongarch/tcg/op_helper.c              |  45 ++--
>   target/loongarch/tcg/tcg_cpu.c                | 107 ++++----
>   target/loongarch/tcg/tlb_helper.c             | 137 ++++++-----
>   18 files changed, 531 insertions(+), 435 deletions(-)
>
Hi,
The files in linux-user/loongarch64/* also need to be modified.

Thanks.
Song Gao
> base-commit: cbf877d67a812be17a9ce404a589e1bdf722c1f6


Re: [PATCH 00/12] target/loongarch: Move CSR registers to struct CPUSysState
Posted by Bibo Mao 4 days, 8 hours ago

On 2026/5/26 下午3:48, gaosong wrote:
> 在 2026/5/26 下午2:50, Bibo Mao 写道:
>> Here new structure CPUSysState is added in CPULoongArchState, CSR
>> registers are move in CPUSysState. In later with LVZ supported, there 
>> will
>> be two copied of CSR registers, so it is simply to add CPUSysState array.
>>
>> Also new field curState is added which points to CPUSysState at
>> beginning, and it can be changed during VM exit/enter entry. There is no
>> function change, all is code movement or variable rename.
>>
>> Bibo Mao (12):
>>    target/loongarch: Add new field curState in CPULoongArchState
>>    target/loongarch: Use curState in cpu.c when accessing CSR registers
>>    target/loongarch: Use curState in cpu_helper.c when accessing CSR
>>      registers
>>    target/loongarch: Use curState in file arch_dump.c when accessing CSR
>>      registers
>>    target/loongarch: Use curState in kvm.c when accessing CSR registers
>>    target/loongarch: Use curState in tlb_helper.c when accessing CSR
>>      registers
>>    target/loongarch: Use curState in tcg_cpu.c when accessing CSR
>>      registers
>>    target/loongarch: Use curState in csr_helper.c when accessing CSR
>>      registers
>>    target/loongarch: Use curState in op_helper.c when accessing CSR
>>      registers
>>    target/loongarch: Add default CSRFL_BASIC info with flags field
>>    target/loongarch: Add wrapper function get_csr_offset()
>>    target/loongarch: Add new structure CPUSysState
>>
>>   hw/intc/loongarch_dintc.c                     |   4 +-
>>   target/loongarch/arch_dump.c                  |   5 +-
>>   target/loongarch/cpu-mmu.h                    |   4 +-
>>   target/loongarch/cpu.c                        | 120 ++++-----
>>   target/loongarch/cpu.h                        |  49 ++--
>>   target/loongarch/cpu_helper.c                 |  41 ++--
>>   target/loongarch/csr.c                        |  10 +-
>>   target/loongarch/csr.h                        |   5 +
>>   target/loongarch/gdbstub.c                    |   3 +-
>>   target/loongarch/kvm/kvm.c                    | 228 +++++++++---------
>>   target/loongarch/machine.c                    | 116 ++++-----
>>   target/loongarch/tcg/constant_timer.c         |  10 +-
>>   target/loongarch/tcg/csr_helper.c             |  55 +++--
>>   .../tcg/insn_trans/trans_extra.c.inc          |  11 +-
>>   .../tcg/insn_trans/trans_privileged.c.inc     |  16 +-
>>   target/loongarch/tcg/op_helper.c              |  45 ++--
>>   target/loongarch/tcg/tcg_cpu.c                | 107 ++++----
>>   target/loongarch/tcg/tlb_helper.c             | 137 ++++++-----
>>   18 files changed, 531 insertions(+), 435 deletions(-)
>>
> Hi,
> The files in linux-user/loongarch64/* also need to be modified.
oops, loongarch-linux-user is missing here. Thanks for the reporting.
Will add and test this target.

Regards
Bibo Mao
> 
> Thanks.
> Song Gao
>> base-commit: cbf877d67a812be17a9ce404a589e1bdf722c1f6