qemu-e2k/target/loongarch
Xiaojuan Yang eb1e9ff8bb target/loongarch: Add lock when writing timer clear reg
There is such error info when running linux kernel:
    tcg_handle_interrupt: assertion failed: (qemu_mutex_iothread_locked()).
    calling stack:
    #0 in raise () at /lib64/libc.so.6
    #1 in abort () at /lib64/libc.so.6
    #2 in g_assertion_message_expr.cold () at /lib64/libglib-2.0.so.0
    #3 in g_assertion_message_expr () at /lib64/libglib-2.0.so.0
    #4 in tcg_handle_interrupt (cpu=0x632000030800, mask=2) at ../accel/tcg/tcg-accel-ops.c:79
    #5 in cpu_interrupt (cpu=0x632000030800, mask=2) at ../softmmu/cpus.c:248
    #6 in loongarch_cpu_set_irq (opaque=0x632000030800, irq=11, level=0)
       at ../target/loongarch/cpu.c:100
    #7 in helper_csrwr_ticlr (env=0x632000039440, val=1) at ../target/loongarch/csr_helper.c:85
    #8 in code_gen_buffer ()
    #9 in cpu_tb_exec (cpu=0x632000030800, itb=0x7fff946ac280, tb_exit=0x7ffe4fcb6c30)
       at ../accel/tcg/cpu-exec.c:358

Add mutex iothread lock around loongarch_cpu_set_irq in csrwr_ticlr() to
fix the bug.

Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220701093407.2150607-10-yangxiaojuan@loongson.cn>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2022-07-04 11:08:58 +05:30
..
insn_trans target/loongarch: Adjust functions and structure to support user-mode 2022-07-04 11:08:58 +05:30
constant_timer.c target/loongarch: Add constant timer support 2022-06-06 18:09:03 +00:00
cpu-csr.h target/loongarch: Add CSRs definition 2022-06-06 18:09:03 +00:00
cpu-param.h target/loongarch: Add MMU support for LoongArch CPU. 2022-06-06 18:09:03 +00:00
cpu.c target/loongarch: Fix the meaning of ECFG reg's VS field 2022-07-04 11:08:58 +05:30
cpu.h target/loongarch: Adjust functions and structure to support user-mode 2022-07-04 11:08:58 +05:30
csr_helper.c target/loongarch: Add lock when writing timer clear reg 2022-07-04 11:08:58 +05:30
disas.c target/loongarch: Add timer related instructions support. 2022-06-06 18:09:03 +00:00
fpu_helper.c target/loongarch: Add floating point move instruction translation 2022-06-06 18:09:03 +00:00
gdbstub.c target/loongarch: remove badaddr from CPULoongArch 2022-07-04 11:08:58 +05:30
helper.h target/loongarch: Adjust functions and structure to support user-mode 2022-07-04 11:08:58 +05:30
insns.decode target/loongarch: Add timer related instructions support. 2022-06-06 18:09:03 +00:00
internals.h target/loongarch: Adjust functions and structure to support user-mode 2022-07-04 11:08:58 +05:30
iocsr_helper.c target/loongarch: Add LoongArch IOCSR instruction 2022-06-06 18:09:03 +00:00
Kconfig hw/loongarch: Add support loongson3 virt machine type. 2022-06-06 18:09:03 +00:00
machine.c target/loongarch: Add MMU support for LoongArch CPU. 2022-06-06 18:09:03 +00:00
meson.build target/loongarch: Add gdb support. 2022-06-06 18:14:13 +00:00
op_helper.c target/loongarch: Adjust functions and structure to support user-mode 2022-07-04 11:08:58 +05:30
README target/loongarch: Update README 2022-07-04 11:08:58 +05:30
tlb_helper.c target/loongarch: Add other core instructions support 2022-06-06 18:09:03 +00:00
translate.c target/loongarch: Add timer related instructions support. 2022-06-06 18:09:03 +00:00
translate.h target/loongarch: Add fixed point arithmetic instruction translation 2022-06-06 18:09:03 +00:00

- Introduction

  LoongArch is the general processor architecture of Loongson.

  The following versions of the LoongArch core are supported
    core: 3A5000
    https://github.com/loongson/LoongArch-Documentation/releases/download/2021.08.17/LoongArch-Vol1-v1.00-EN.pdf

  We can get the latest loongarch documents at https://github.com/loongson/LoongArch-Documentation/tags.


- System emulation

  Mainly emulate a virt 3A5000 board and ls7a bridge that is not exactly the same as the host.
  3A5000 support multiple interrupt cascading while here we just emulate the extioi interrupt
  cascading. LS7A1000 host bridge support multiple devices, such as sata, gmac, uart, rtc
  and so on. But we just realize the rtc. Others use the qemu common devices. It does not affect
  the general use. We also introduced the emulation of devices at docs/system/loongarch/loongson3.rst.

  This version only supports running binary files in ELF format, and does not depend on BIOS and kernel file.
  You can compile the test program with 'make & make check-tcg' and run the test case with the following command:

  1. Install LoongArch cross-tools on X86 machines.

    Download cross-tools.

      wget https://github.com/loongson/build-tools/releases/download/2022.05.29/loongarch64-clfs-5.0-cross-tools-gcc-full.tar.xz

      tar -vxf loongarch64-clfs-5.0-cross-tools-gcc-full.tar.xz -C /opt

    Config cross-tools env.

      . setenv.sh

      setenv.sh:

          #!/bin/sh
          set -x
          CC_PREFIX=/opt/cross-tools

          export PATH=$CC_PREFIX/bin:$PATH
          export LD_LIBRARY_PATH=$CC_PREFIX/lib:$LD_LIBRARY_PATH
          export LD_LIBRARY_PATH=$CC_PREFIX/loongarch64-unknown-linux-gnu/lib/:$LD_LIBRARY_PATH
          set +x

  2. Test tests/tcg/multiarch.

    ./configure --disable-rdma --disable-pvrdma --prefix=/usr  \
            --target-list="loongarch64-softmmu"  \
            --disable-libiscsi --disable-libnfs --disable-libpmem \
            --disable-glusterfs --enable-libusb --enable-usb-redir \
            --disable-opengl --disable-xen --enable-spice --disable-werror \
            --enable-debug --disable-capstone --disable-kvm --enable-profiler

    cd  build/

    make && make check-tcg

    or

    ./build/qemu-system-loongarch64 -machine virt -m 4G -cpu Loongson-3A5000 -smp 1 -kernel build/tests/tcg/loongarch64-softmmu/hello -monitor none -display none -chardev file,path=hello.out,id=output -serial chardev:output

- Linux-user emulation

  We already support Linux user emulation. We can use LoongArch cross-tools to build LoongArch executables on X86 machines,
  and We can also use qemu-loongarch64 to run LoongArch executables.

  1. Config cross-tools env.

     see System emulation.

  2. Test tests/tcg/multiarch.

     ./configure  --static  --prefix=/usr  --disable-werror --target-list="loongarch64-linux-user" --enable-debug

     cd build

     make && make check-tcg

  3. Run LoongArch system basic command with loongarch-clfs-system.

     - Config clfs env.

       wget https://github.com/loongson/build-tools/releases/download/2022.05.29/loongarch64-clfs-system-5.0.tar.bz2

       tar -vxf loongarch64-clfs-system-5.0.tar.bz2 -C /opt/clfs

       cp /opt/clfs/lib64/ld-linux-loongarch-lp64d.so.1  /lib64

       export LD_LIBRARY_PATH="/opt/clfs/lib64"

     - Run LoongArch system basic command.

       ./qemu-loongarch64  /opt/clfs/usr/bin/bash
       ./qemu-loongarch64  /opt/clfs/usr/bin/ls
       ./qemu-loongarch64  /opt/clfs/usr/bin/pwd

- Note.
  We can get the latest LoongArch documents or LoongArch tools at https://github.com/loongson/