Skip to content

Instantly share code, notes, and snippets.

@rakslice
Last active July 21, 2023 07:03
Show Gist options
  • Save rakslice/720171089c1d0e42d2b968caf05502d5 to your computer and use it in GitHub Desktop.
Save rakslice/720171089c1d0e42d2b968caf05502d5 to your computer and use it in GitHub Desktop.
idle hlt monkey patch for old solaris x86
#!/bin/sh
set -e
set -x
# idle hlt monkey patch for old solaris x86
# based on ian northeast's alt.solaris.x86 post from 2003
# https://groups.google.com/g/alt.solaris.x86/c/eCi8GKouFqg/m/jCnUnhhN7X4J
readval() # Usage: readval {adb address and verb} {type modifier}
{
# TODO if adb has a mode without stdout spam use it instead of this marker business
echo "$1\"marker \"$2" | adb -k /dev/ksyms /dev/mem | sed -n 's/^.*marker \(.*\)$/\1/p'
}
offset=0x34 # offset of call to idle_cpu in idle
# double check the offset by making sure the instruction there is
# what we expect
# If the offset is wrong for your system, go look at the disassembly of idle
# echo "idle,25?ai" | adb -k /dev/ksyms /dev/mem
# and find the offset of the call instruction that calls idle_cpu
# TODO automate that
# check the opcode
if [ "`readval "idle+$offset?" x`" != "15ff" ] # call 32-bit literal
then
exit 1
fi
# check the operand
idle_cpu=`readval idle_cpu= X` # address of idle_cpu()
if [ "`readval "idle+$offset+2?" X`" != "$idle_cpu" ]
then
exit 1
fi
cat > /tmp/sol-idle <<eof
idle+$offset/"Inserting a temporary jmp 0x04"
idle+$offset/w 0x04e8
idle+$offset+2/"Smashing in the final NOP;NOP;NOP;NOP"
idle+$offset+2/W 0x90909090
idle+$offset/"Smashing in the initial HLT;NOP"
idle+$offset/w 0x90f4
idle+$offset/"Final result: call [idle_cpu] --> HLT;NOP;NOP;NOP;NOP;NOP"
eof
/usr/bin/adb -w -k /dev/ksyms /dev/mem < /tmp/sol-idle
rm /tmp/sol-idle
@rakslice
Copy link
Author

rakslice commented Jul 21, 2023

This probably works largely unmodified on whatever svr4's are close enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment