[Vm-dev] magic decode for image files

David T. Lewis lewis at mail.msen.com
Mon Apr 10 23:33:32 UTC 2017


On Mon, Apr 10, 2017 at 07:31:47PM +0530, K K Subbu wrote:
> 
> On Monday 10 April 2017 06:52 PM, David T. Lewis wrote:
> >
> >Very nice :-)
> >
> >See also the ckformat program, which is automatically generated as an 
> >executeable
> >from package ImageFormat in the VMMaker repository. It is used for 
> >selecting
> >the appropriate VM for a given image file in the traditional interpreter VM
> >in the /usr/local/bin/squeak script.
> 
> I saw the ckformat program and couldn't see why it was needed. Perhaps I 
> am missing something here.

It answers the image format number on standard output, for use in shell scripts.

The attached "run" file is the script that I use on my own PC to select Spur 64,
Spur 32 bit, Cog 32 bit, interpreter VM 64 bit, or interpreter VM 32 bit.

The start script for interpreter VM uses this approach also:
http://squeakvm.org/cgi-bin/viewvc.cgi/squeak/trunk/platforms/unix/cmake/squeak.in?revision=3609&view=markup

> 
> If we generate magic and binfmt_misc registrations, then 
> package-managers can launch the right vm for any image file. It also 
> integrates well with other utilities like update-binfmts.
> 
> Regards .. Subbu

That approach would work also.

Your magic decode logic is nice, do you mind if I steal it and add it to ImageFormat?

Thanks,
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