[Vm-dev] Determining which VM to run from a shell script (was: VM Maker: ImageFormat-dtl.7.mcz)

David T. Lewis lewis at mail.msen.com
Sat Jan 1 18:16:19 UTC 2011


Attached is a shell script "vmrun" that I am now using on my
Linux box. It runs Cog where possible, and either the 32 or 64
bit standard interpreter for other images. This is something of
a hack to be sure, but it seems to work.

Bert, I think this is more or less what you were suggesting earlier
for automating the VM selection.

BTW, another reasonable way to attack this problem is to use the
VM itself. A standard interpreter already knows how to parse all
the command arguments, find the image file, read the image, and
determine the image format. A 32 bit VM can read all of the image
formats including Cog. All that is needed is to export an additional
function from the interpreter and wire it into a command line option
in the Unix support code. In this scenario, the VM itself serves
as the "ckformat" utility, and the vmrun script would not need to
parse arguments or search for the image file. If anyone thinks this
approach would be better I can post the changes (I tried it on my
system and it worked fine).

Dave


On Fri, Dec 31, 2010 at 06:44:34PM -0500, David T. Lewis wrote:
>  
> Attached are a shell script to illustrated use of ckformat as well as
> a copy of the C source generated from ImageFormat.
> 
> Happy New Year!
> 
> Dave
> 
> On Sat, Jan 01, 2011 at 12:40:21AM +0000, squeak-dev-noreply at lists.squeakfoundation.org wrote:
> > Dave Lewis uploaded a new version of ImageFormat to project VM Maker:
> > http://www.squeaksource.com/VMMaker/ImageFormat-dtl.7.mcz
> > 
> > ==================== Summary ====================
> > 
> > Name: ImageFormat-dtl.7
> > Author: dtl
> > Time: 31 December 2010, 6:40:20 am
> > UUID: a8499caf-2b80-4c5c-82e7-e2b10455f42a
> > Ancestors: ImageFormat-dtl.6
> > 
> > Generate ckformat.c, a utility program for reading the image file format number from an image file. The ckformat program is intended for testing image file format from a unix shell script such that the shell script can select a VM based on image requirements. A non-zero return status code from ckformat indicates failure, otherwise the format number is written to standard output with no line terminator. The utility handles big-endian and little-endian versions of all known 32 and 64 bit image formats.
> > 
> > The ckformat C code is generated from ImageFormat to ensure that it is updated as new format numbers are assigned and documented in class ImageFormat.



-------------- next part --------------
#!/bin/sh
# Sat Jan  1 12:32:21 EST 2011
#
# vmrun utility script
#
# Select a VM and run an image based on the image format number
#
# Assume that /usr/local/bin/squeak runs the traditional VM,
# /usr/local/bin/cog runs Cog, and /usr/local/bin/squeak64 runs
# a traditional intepreter VM compiled for 64-bit images.
#
# Use ckformat to determine image requirements. See package
# ImageFormat in the SqueakSource VMMaker repository. To
# generate C source for the ckformat utility, evaluate
#    "ImageFormat createCkStatusProgram"
#

BASEDIR="/usr/local"
BIN=$BASEDIR/bin
CKFORMAT="$BIN/ckformat"   # The ckformat utility
INTERP="$BIN/squeak"       # Standard 32-bit interpreter, all 32-bit images
INTERP_64="$BIN/squeak64"  # Standard interpreter for 64-bit images
COG="$BIN/cog"             # Cog VM for 32-bit images with closure support

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 test ! ${IMAGENAME}
then
  echo $0: no image file specified in $@
  exit 1
fi

case $NUM in
6502)
  VM=$INTERP;;
6504 | 6505)
  VM=$COG;;
68000 | 68002 | 68003)
  VM=$INTERP_64;;
*)  echo image format $NUM not recognized;
  exit -1;;
esac

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vmrun.zip
Type: application/zip
Size: 917 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20110101/c7706060/vmrun.zip


More information about the Vm-dev mailing list