[Vm-dev] magic decode for image files
David T. Lewis
lewis at mail.msen.com
Tue Apr 11 12:03:30 UTC 2017
On Tue, Apr 11, 2017 at 12:47:57PM +0530, K K Subbu wrote:
>
> On Tuesday 11 April 2017 05:03 AM, David T. Lewis wrote:
> >On Mon, Apr 10, 2017 at 07:31:47PM +0530, K K Subbu wrote:
> >>
> >>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
>
> I use the commonly available od(1) to extract magic numbers:
>
> $ alias sqmagic='od -An -N4 -t x1'
> $ sqmagic SpurVMMaker.image
> 79 19 00 00
> $
>
> The case statement duplicates binfmt_misc registrations. Each image
> format requires a just a single line to register with binfmt_misc. E.g.
>
> # :name:type:offset:pattern:mask:interpreter:flags
>
> $ echo ':spur32le:M::\x79\x19\x00\x00::/opt/squeak/spur32:' | sudo tee
> /proc/sys/fs/binfmt_misc/register
>
> and removed with
> $ echo -1 | sudo tee /proc/sys/fs/binfmt_misc/spur32le
>
> The run script is fragile (e.g. it will break if $0 is symlink). If the
> disambiguation can be done outside, then it can be simplified without
> losing flexibility.
>
> Other interpreters/emulators like python, lua, qemu work this way.
>
> >>
> >>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?
>
> Please do. It is very nice of you to offer me to help merge the code.
> Thanks. I am still in the catchup mode :-(. The magic file has to be
> generated just like any other .c file. It can be compiled into a binary
> file with "file -C ..." into magic.mgc bin file but that would be an
> overkill for such a small file.
>
> Regards .. Subbu
Thanks, I added it to ImageFormat. One thing needed changing for 64-bit
formats on little-endian, where the format number is written to the second
four bytes (offset 4). The following seems to work now for all formats:
# Smalltalk image file formats
0 lelong 6502 Smalltalk image V3 32-bit no closure no native float (6502)
0 belong 6502 Smalltalk image V3 32-bit no closure no native float (6502)
0 lelong 6504 Smalltalk image V3 32-bit closure no native float (6504)
0 belong 6504 Smalltalk image V3 32-bit closure no native float (6504)
0 lelong 68000 Smalltalk image V3 64-bit no closure no native float (68000)
4 belong 68000 Smalltalk image V3 64-bit no closure no native float (68000)
0 lelong 68002 Smalltalk image V3 64-bit closure no native float (68002)
4 belong 68002 Smalltalk image V3 64-bit closure no native float (68002)
0 lelong 6505 Smalltalk image V3 32-bit closure native float (6505)
0 belong 6505 Smalltalk image V3 32-bit closure native float (6505)
0 lelong 68003 Smalltalk image V3 64-bit closure native float (68003)
4 belong 68003 Smalltalk image V3 64-bit closure native float (68003)
0 lelong 6521 Smalltalk image Spur 32-bit closure native float (6521)
0 belong 6521 Smalltalk image Spur 32-bit closure native float (6521)
0 lelong 68019 Smalltalk image Spur 64-bit closure native float (68019)
4 belong 68019 Smalltalk image Spur 64-bit closure native float (68019)
0 lelong 68021 Smalltalk image Spur 64-bit closure native float (68021)
4 belong 68021 Smalltalk image Spur 64-bit closure native float (68021)
Dave
More information about the Vm-dev
mailing list