xref: /DragonOS/tools/run-qemu.sh (revision 2291ffdece1dc5a703602f79f74df8a4854d215b)
1# 进行启动前检查
2flag_can_run=1
3ARGS=`getopt -o p -l bios: -- "$@"`
4eval set -- "${ARGS}"
5echo "$@"
6allflags=$(qemu-system-x86_64 -cpu help | awk '/flags/ {y=1; getline}; y {print}' | tr ' ' '\n' | grep -Ev "^$" | sed -r 's|^|+|' | tr '\n' ',' | sed -r "s|,$||")
7
8# 请根据自己的需要,在-d 后方加入所需的trace事件
9
10# 标准的trace events
11qemu_trace_std=cpu_reset,guest_errors,exec,cpu
12# 调试usb的trace
13qemu_trace_usb=trace:usb_xhci_reset,trace:usb_xhci_run,trace:usb_xhci_stop,trace:usb_xhci_irq_msi,trace:usb_xhci_irq_msix,trace:usb_xhci_port_reset,trace:msix_write_config,trace:usb_xhci_irq_msix,trace:usb_xhci_irq_msix_use,trace:usb_xhci_irq_msix_unuse,trace:usb_xhci_irq_msi,trace:usb_xhci_*
14qemu_accel=kvm
15if [ $(uname) == Darwin ]; then
16    qemu_accel=hvf
17fi
18
19
20QEMU=qemu-system-x86_64
21QEMU_DISK_IMAGE="../bin/disk.img"
22QEMU_MEMORY="512M"
23QEMU_SMP="2,cores=2,threads=1,sockets=1"
24QEMU_MONITOR="stdio"
25QEMU_TRACE="${qemu_trace_std}"
26QEMU_CPU_FEATURES="IvyBridge,apic,x2apic,+fpu,check,${allflags}"
27QEMU_RTC_CLOCK="clock=host,base=localtime"
28QEMU_SERIAL="file:../serial_opt.txt"
29QEMU_DRIVE="id=disk,file=${QEMU_DISK_IMAGE},if=none"
30
31QEMU_DEVICES="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -net nic,model=virtio -usb -device qemu-xhci,id=xhci,p2=8,p3=4 -machine accel=${qemu_accel}"
32
33QEMU_ARGUMENT="-d ${QEMU_DISK_IMAGE} -m ${QEMU_MEMORY} -smp ${QEMU_SMP} -boot order=d -monitor ${QEMU_MONITOR} -d ${qemu_trace_std} "
34
35QEMU_ARGUMENT+="-s -S -cpu ${QEMU_CPU_FEATURES} -rtc ${QEMU_RTC_CLOCK} -serial ${QEMU_SERIAL} -drive ${QEMU_DRIVE} ${QEMU_DEVICES}"
36
37
38if [ $flag_can_run -eq 1 ]; then
39    case "$1" in
40        --bios)
41      case "$2" in
42              uefi) #uefi启动新增ovmf.fd固件
43              ${QEMU} -bios arch/X86_64/OVMF.fd ${QEMU_ARGUMENT}
44            ;;
45              legacy)
46              ${QEMU} ${QEMU_ARGUMENT}
47              ;;
48            esac
49
50esac
51else
52  echo "不满足运行条件"
53fi
54