#!/bin/bash

VM=$1

if [ $VM -lt 8 ]; then
	REG=$((0x153c + $VM * 4))
else
	REG=$((0x1438 + ($VM - 8) * 4))
fi

REG=$(printf "0x%x" $REG)

ADDR=$(sudo /usr/src/radeontool/radeonreg --skip=0 regmatch $REG | cut -c 8-17)

VRAM=/sys/kernel/debug/dri/0/radeon_vram

sudo hexdump -s ${ADDR}000 -n 4096 -e '"%010.10_ax  " 2/4 "%08x " "\n"' $VRAM | while read l
do
	echo "$l"
	ADDR=$(echo "$l" | cut -c 13-17)
	if [ "$VM" -ne 0 -a "$ADDR" != "00000" -a "$ADDR" != "" ]; then
		sudo hexdump -s 0x${ADDR}000 -n 4096 -e '"   %010.10_ax  " 2/4 "%08x " "\n"' $VRAM
	fi
done
