#!/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]}

qemu-system-aarch64 \
  --snapshot \
  -machine virt,gic-version=max,mte=on \
  -initrd ./rootfs.img \
  -kernel ./Image \
  -net nic -net user,hostfwd=tcp::${SSH_PORT}-:22 \
  -append "init=/init nokaslr" \
  -nographic \
  -monitor tcp:127.0.0.1:45454,server,nowait \
  -smp cores=4 \
  -cpu max \
  -s
