#!/bin/bash

# init ssh port
if [ -z $1 ];
then
	SSH_PORT=10069
else
	SSH_PORT=$1
fi

# init core number
if [ -z $2 ]; then
	CORE_NUM=4
else
	CORE_NUM=$2
fi

# init memory size
if [ -z $3 ];
then
	MEM_SIZE=4G
else
	MEM_SIZE=$3
fi

# resolve image path
list=($(pwd)/img/*.img)
IMAGE=${list[0]}

  #-kernel ../debug_setup/debug_bzImage \
  #-kernel ./mantic_bzImage \
  #-append "console=ttyS0 root=/dev/sda debug earlyprintk=serial panic=1000 kaslr smap smep selinux=0 tsc=unstable net.ifnames=0" \
qemu-system-aarch64 \
  --snapshot \
  -m 4G \
  -machine virt,gic-version=max,mte=on \
  -initrd ./rootfs.img \
  -kernel ./vmlinuz-6.5.0-45-generic \
  -net nic -net user,hostfwd=tcp::${SSH_PORT}-:22 \
  -append "init=/init nokaslr kasan.mode=on" \
  -nographic \
  -monitor tcp:127.0.0.1:45454,server,nowait \
  -smp cores=4 \
  -cpu max \
  -s
