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|,$||") 7ARCH="x86_64" 8#ARCH="i386" 9# 请根据自己的需要,在-d 后方加入所需的trace事件 10 11# 标准的trace events 12qemu_trace_std=cpu_reset,guest_errors,exec,cpu 13# 调试usb的trace 14qemu_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_* 15qemu_accel=kvm 16if [ $(uname) == Darwin ]; then 17 qemu_accel=hvf 18fi 19 20 21QEMU=qemu-system-x86_64 22QEMU_DISK_IMAGE="../bin/disk.img" 23QEMU_MEMORY="512M" 24QEMU_SMP="2,cores=2,threads=1,sockets=1" 25QEMU_MONITOR="stdio" 26QEMU_TRACE="${qemu_trace_std}" 27QEMU_CPU_FEATURES="IvyBridge,apic,x2apic,+fpu,check,${allflags}" 28QEMU_RTC_CLOCK="clock=host,base=localtime" 29QEMU_SERIAL="file:../serial_opt.txt" 30QEMU_DRIVE="id=disk,file=${QEMU_DISK_IMAGE},if=none" 31 32QEMU_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}" 33 34QEMU_ARGUMENT="-d ${QEMU_DISK_IMAGE} -m ${QEMU_MEMORY} -smp ${QEMU_SMP} -boot order=d -monitor ${QEMU_MONITOR} -d ${qemu_trace_std} " 35 36QEMU_ARGUMENT+="-s -S -cpu ${QEMU_CPU_FEATURES} -rtc ${QEMU_RTC_CLOCK} -serial ${QEMU_SERIAL} -drive ${QEMU_DRIVE} ${QEMU_DEVICES}" 37 38 39if [ $flag_can_run -eq 1 ]; then 40 case "$1" in 41 --bios) 42 case "$2" in 43 uefi) #uefi启动新增ovmf.fd固件 44 if [ ${ARCH} == x86_64 ] ;then 45 ${QEMU} -bios arch/x86_64/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT} 46 elif [ ${ARCH} == i386 ] ;then 47 ${QEMU} -bios arch/i386/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT} 48 fi 49 ;; 50 legacy) 51 ${QEMU} ${QEMU_ARGUMENT} 52 ;; 53 esac 54 55esac 56else 57 echo "不满足运行条件" 58fi 59