[Vm-dev] [Pharo-users] VM/Image magic numbers (Re: Pharo 6 snap install)

David T. Lewis lewis at mail.msen.com
Tue Apr 18 22:17:44 UTC 2017


On Tue, Apr 18, 2017 at 11:11:07PM +0200, Luke Gorrie wrote:
>  
> On 15 April 2017 at 01:22, Ben Coman <btc at openinworld.com> wrote:
> 
> > The "magic decode for image files" seems related and possibly *very*
> > useful....
> > http://forum.world.st/magic-decode-for-image-files-td4941712.html#a4941837
> >
> > Now traditionally the VM has been backward compatible with old Images,
> > but Pharo doesn't necessarily adhere to that and policy IIUC is
> > release specific VM/Image pairs.
> > So does Pharo require extra magic numbers to co-ordinate this?
> > And how would this interact with OpenSmalltalk policy on these magic
> > numbers?
> >
> 
> I would really like a copy of the script that checks the magic number and
> starts the right VM. David, could you share yours please?

Attached.

Dave

-------------- next part --------------
#!/bin/sh
# dtl Wed May 20 19:49:25 EDT 2015
# Mon Apr 10 19:18:47 EDT 2017
#
# VM run utility script, typicially installed as /usr/local/bin/run
# usage: run <myimage>
#
# Select a VM and run an image based on the image format number
#
# Assume that /usr/local/bin/squeak runs the traditional VM for 32-bit
# and 64-bit images in the traditional image formats. Assume that
# /usr/local/bin/cog runs Cog, /usr/local/bin/spur runs the VM for 32-bit
# Spur images, and /usr/local/bin/spur64 runs the VM for 64-bit Spur
# images.
#
# Use ckformat to determine image requirements. See package ImageFormat
# in the SqueakSource VMMaker repository. The executable is distributed
# with the standard interpreter VM. To generate C source for the ckformat
# utility, evaluate:
#    "ImageFormat createCkStatusProgram"
#

# VMs look for this default name if an image has not been
# specified. Use the same default for this script.
DEFAULT_IMAGENAME="squeak.image"

# Scripts for running various interpreters
INTERP_SCRIPT="squeak"       # Context VM for 32 and 64 bit images
COG_SCRIPT="cog"             # Cog VM
SPUR_SCRIPT="spur"           # Spur VM for 32-bit Spur image
SPUR64_SCRIPT="spur64"       # Spur VM for 64-bit Spur image

# Assume scripts are in the same directory, e.g. /usr/local/bin
BIN=`dirname "$0"`

# The ckformat utility is distributed with interpreter VM builds.
# Find it in the lib directory for the interpreter VM.
CKFORMAT=`squeak -version | grep 'plugin path' | sed 's/^.*default: //' | sed 's/]$//'`ckformat

# Paths to the run scripts
INTERP="$BIN/$INTERP_SCRIPT" # Context interpreter VM
COG="$BIN/$COG_SCRIPT"       # Cog VM for 32-bit images with closure support
SPUR="$BIN/$SPUR_SCRIPT"     # Spur VM for Spur 32-bit image format 6521
SPUR64="$BIN/$SPUR64_SCRIPT" # Spur VM for Spur 64-bit image format 68109

for arg in $*
do
  case ${arg} in
  -*) #ignore
    ;;
  *) # either and option argument or the image name
    if test -f ${arg}
    then
      NUM=`${CKFORMAT} ${arg} 2>/dev/null`
      if test $? -eq 0
      then
        IMAGENAME=${arg}
        break
      fi
    else
      if test -f ${arg}.image
      then
        NUM=`${CKFORMAT} ${arg}.image 2>/dev/null`
        if test $? -eq 0
        then
          IMAGENAME=${arg}.image
          break
        fi
      fi
    fi
    ;;
  esac
done

# if no image name specified on command line, try the default
if test ! ${IMAGENAME}
then
  if test -f ${DEFAULT_IMAGENAME}
  then
    IMAGENAME=${DEFAULT_IMAGENAME}
    NUM=`${CKFORMAT} ${IMAGENAME} 2>/dev/null`
    if test $? -ne 0
    then
      echo image format ${NUM} not recognized for ${IMAGENAME}
      exit 1
    fi
  else
    echo `basename $0` $@: image file not found
    exit 1
  fi
fi

case $NUM in
  6502)
    VM=$INTERP
    ;;
  6504 | 6505)
    VM=$COG
    ;;
  6521)
    VM=$SPUR
    ;;
  68000 | 68002 | 68003)
    VM=$INTERP
    ;;
  68019)
    VM=$SPUR64 # early spur 64
    ;;
  68021)
    VM=$SPUR64
    ;;
  *)  echo image format ${NUM} not recognized for ${IMAGENAME}
    exit -1;;
esac

# Use standard VM as default if preferred VM not present
if test ! -x ${VM}
then
  echo ${VM} not found, using ${INTERP}
  VM="${INTERP}"
fi

### echo running ${IMAGENAME} with image format $NUM using $VM
exec ${VM} $@



More information about the Vm-dev mailing list