CloverBootloader/Qemu/gdb_launch

145 lines
3.3 KiB
Plaintext
Raw Normal View History

2020-03-09 10:13:38 +01:00
SCRIPT_ABS_FILENAME=`LC_ALL=en_US.ISO8859-1 perl -e 'use Cwd "abs_path";print abs_path(shift)' "${BASH_SOURCE[0]}"`
SCRIPT_DIR=`dirname "$SCRIPT_ABS_FILENAME"`
OSTYPE=`uname -s`
2020-03-09 13:16:31 +01:00
#echo $OSTYPE
2020-03-09 10:13:38 +01:00
if [ -z "$1" ]
then
2020-03-09 13:16:31 +01:00
if [ -f "$SCRIPT_DIR"/../Build/Clover/DEBUG_GCC53/X64/CLOVERX64.debug ]
then
clover_debug_file="$SCRIPT_DIR"/../Build/Clover/DEBUG_GCC53/X64/CLOVERX64.debug
echo Using default file "$clover_debug_file"
else
echo "Usage: $SCRIPT_ABS_FILENAME [Clover debug file]"
exit 1
fi
else
clover_debug_file="${1%.*}".debug
fi
if ! [ -f "$clover_debug_file" ]
then
echo Debug file "$clover_debug_file" doesn\'t exist
exit 1
fi
clover_efi_file="${clover_debug_file%.*}".efi
if ! [ -f "$clover_efi_file" ]
then
echo Efi file "$clover_efi_file" doesn\'t exist
exit 1
2020-03-09 10:13:38 +01:00
fi
echo clover_debug_file="$clover_debug_file"
2020-03-09 13:16:31 +01:00
echo clover_efi_file="$clover_efi_file"
2020-03-09 10:13:38 +01:00
set -x
if [ "$OSTYPE" = "Darwin" ]
then
2021-03-24 22:19:01 +01:00
if ! [ -f ./Qemu/qemu_portable/qemu-system-x86_64 ]
2020-03-09 10:13:38 +01:00
then
2021-03-24 22:19:01 +01:00
echo "You must restore the folder \'qemu_portable\'"
2020-03-09 10:13:38 +01:00
exit 1
fi
if ! [ -f "$SCRIPT_DIR"/disk_image_gpt.img ]
then
unzip -o "$SCRIPT_DIR"/disk_image_gpt.img.zip -d "$SCRIPT_DIR"
2020-03-09 10:13:38 +01:00
rm -rf "$SCRIPT_DIR"/__MACOSX
fi
if pgrep qemu
then
killall qemu-system-x86_64
fi
> "$SCRIPT_DIR"/serial0_qemu_out.log # empty file without erasing it. Useful for editor for refreshing and reloading.
hdiutil attach "$SCRIPT_DIR"/disk_image_gpt.img || exit 1
2020-03-09 13:16:31 +01:00
shopt -s nocasematch
if [[ "$(basename "$clover_debug_file")" =~ "CloverX64"* ]]
2020-03-09 10:13:38 +01:00
then
echo ditto "${clover_debug_file%.*}".efi /Volumes/QEMU_EFI/EFI/CLOVER/CLOVERX64.efi
ditto "${clover_debug_file%.*}".efi /Volumes/QEMU_EFI/EFI/CLOVER/CLOVERX64.efi || exit 1
echo ditto "${clover_debug_file%.*}".efi /Volumes/QEMU_EFI/EFI/BOOT/BOOTX64.efi
ditto "${clover_debug_file%.*}".efi /Volumes/QEMU_EFI/EFI/BOOT/BOOTX64.efi || exit 1
else
: # TODO : if it's a module, has to be copied in Drivers
fi
2020-03-09 13:16:31 +01:00
shopt -u nocasematch
2020-03-09 10:13:38 +01:00
diskutil eject /Volumes/QEMU_EFI || exit 1
2020-03-09 13:16:31 +01:00
sleep 1 # not 100% sure it's needed
2020-03-09 10:13:38 +01:00
set -m
2021-03-24 22:19:01 +01:00
cd "$SCRIPT_DIR"
./qemu_portable/qemu-system-x86_64 \
-L qemu_portable \
2020-03-09 13:16:31 +01:00
-m 2048 \
2021-03-24 22:19:01 +01:00
-cpu Penryn \
-bios ./bios.bin-1.13.0 \
2020-03-09 13:16:31 +01:00
-machine q35 \
-device ahci,id=ahi \
2021-03-24 22:19:01 +01:00
-drive format=raw,id=hda,file=./disk_image_gpt.img \
2020-03-09 13:16:31 +01:00
-usb \
-device usb-mouse,bus=usb-bus.0,port=2 \
-device usb-kbd,bus=usb-bus.0,port=1 \
2021-03-24 22:19:01 +01:00
-serial file:./serial0_qemu_out.log \
2020-03-09 13:16:31 +01:00
-gdb tcp::9000 &
[[ $? == 0 ]] || exit 1
set +m
2020-03-09 10:13:38 +01:00
count=1
timeout=60
2021-03-24 22:19:01 +01:00
image_base_str="CloverX64 : Image base = "
2020-03-09 10:13:38 +01:00
2021-03-24 22:19:01 +01:00
getImageBase() {
2020-03-09 10:13:38 +01:00
[ -f "$SCRIPT_DIR"/serial0_qemu_out.log ] || return 1
grep "$image_base_str" "$SCRIPT_DIR"/serial0_qemu_out.log
return $?
}
while [ $count -le $timeout ] && ! getImageBase
do
sleep 1
count=$((count+1))
done
if [ $count -ge $timeout ]
then
echo Cannot find "\"Clover : Image base = \"" in "$SCRIPT_DIR"/serial0_qemu_out.log after $timeout seconds
exit 1
fi
2021-03-24 22:19:01 +01:00
adr="$(grep "$image_base_str" ./serial0_qemu_out.log | awk '{printf "0x%x",$6}')"
2020-03-09 10:13:38 +01:00
echo adr="$adr"
2021-03-24 22:19:01 +01:00
GDB=gdb
if [ -f ../../../toolchain.gdb/gdb ]
then
GDB=../../../toolchain.gdb/gdb
fi
"$GDB" --eval-command="file "$clover_debug_file" -o $adr" \
2020-03-09 10:13:38 +01:00
--eval-command="target remote localhost:9000" \
--eval-command="rwatch *0" \
2020-04-06 13:35:06 +02:00
--eval-command="br panic_" \
2020-03-09 10:13:38 +01:00
--eval-command="continue"
exit 0
fi