From: Rayiner Hashem
Subject: Macros are pretty neat...
Date: 
Message-ID: <1179053885.413854.196650@l77g2000hsb.googlegroups.com>
Having some free time this week, I decided to do some Lisping. Chose a
simple enough problem: an amd64 assembler. 500 lines of (commented)
code later, I've got a macro language that let's me take an
instruction description from Intel or AMD's manuals:

(define-encoder mov (dest source)
  ((rm8 r8) (#x88 /r))
  ((rm32 r32) (#x89 /r))
  ((rm64 r64) (#x89 /r))
  ((r8 rm8) (#x8A /r))
  ((r32 rm32) (#x8B /r))
  ((r64 rm64) (#x8B /r))
  ((r8 imm8) (#xB0 +r))
  ((r32 imm32) (#xB8 +r))
  ((r64 imm64) (#xB8 +r))
  ((rm8 imm8) (#xC6 /0 ib))
  ((rm32 imm32) (#xC7 /0 id))
  ((rm64 imm32) (#xC7 /0 id)))

and turn it into an efficient encoding function that takes a line of
assembly and spits out some bytes (no interpreting pattern tables at
runtime!)

So thanks to Lisp, the rest of the program is clerical work,
transcribing AMD's manuals while focusing most of my attention on CSI:
Miami...

Maybe its a failure of imagination, but I honestly cannot fathom doing
this in any language other than Lisp. Maybe if this was some super-
regular RISC architecture there'd be a neat 10-line purely-functional
Haskell program, but for something unabashedly hairy as x86?

From: Ari Johnson
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <m2wszcbxh1.fsf@hermes.theari.com>
Rayiner Hashem <·······@gmail.com> writes:

> Having some free time this week, I decided to do some Lisping. Chose a
> simple enough problem: an amd64 assembler. 500 lines of (commented)
> code later, I've got a macro language that let's me take an
> instruction description from Intel or AMD's manuals:
>
> (define-encoder mov (dest source)
>   ((rm8 r8) (#x88 /r))
>   ((rm32 r32) (#x89 /r))
>   ((rm64 r64) (#x89 /r))
>   ((r8 rm8) (#x8A /r))
>   ((r32 rm32) (#x8B /r))
>   ((r64 rm64) (#x8B /r))
>   ((r8 imm8) (#xB0 +r))
>   ((r32 imm32) (#xB8 +r))
>   ((r64 imm64) (#xB8 +r))
>   ((rm8 imm8) (#xC6 /0 ib))
>   ((rm32 imm32) (#xC7 /0 id))
>   ((rm64 imm32) (#xC7 /0 id)))
>
> and turn it into an efficient encoding function that takes a line of
> assembly and spits out some bytes (no interpreting pattern tables at
> runtime!)
>
> So thanks to Lisp, the rest of the program is clerical work,
> transcribing AMD's manuals while focusing most of my attention on CSI:
> Miami...
>
> Maybe its a failure of imagination, but I honestly cannot fathom doing
> this in any language other than Lisp. Maybe if this was some super-
> regular RISC architecture there'd be a neat 10-line purely-functional
> Haskell program, but for something unabashedly hairy as x86?

Is this something you'd consider showing off to the public?  I was
working on an m68k assembler in CL and haven't had time to work on it
lately, but it's still fledgling enough to benefit from others'
thinking.
From: Alan Crowe
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <86k5vczhc3.fsf@cawtech.freeserve.co.uk>
Rayiner Hashem <·······@gmail.com> writes:

> Having some free time this week, I decided to do some Lisping. Chose a
> simple enough problem: an amd64 assembler. 500 lines of (commented)
> code later, I've got a macro language that let's me take an
> instruction description from Intel or AMD's manuals:
> 
> (define-encoder mov (dest source)
>   ((rm8 r8) (#x88 /r))
>   ((rm32 r32) (#x89 /r))
>   ((rm64 r64) (#x89 /r))
>   ((r8 rm8) (#x8A /r))
>   ((r32 rm32) (#x8B /r))
>   ((r64 rm64) (#x8B /r))
>   ((r8 imm8) (#xB0 +r))
>   ((r32 imm32) (#xB8 +r))
>   ((r64 imm64) (#xB8 +r))
>   ((rm8 imm8) (#xC6 /0 ib))
>   ((rm32 imm32) (#xC7 /0 id))
>   ((rm64 imm32) (#xC7 /0 id)))
> 
> and turn it into an efficient encoding function that takes a line of
> assembly and spits out some bytes (no interpreting pattern tables at
> runtime!)

Sounds very interesting. Can you post it?

Alan Crowe
Edinburgh
Scotland
From: Rayiner Hashem
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <1179104115.854068.142680@h2g2000hsg.googlegroups.com>
If this is a dupe, I blame Google Groups for propagating my last
message attempt slowly :-/

Anyway, the code is here: http://www.prism.gatech.edu/~gtg990h/amd64asm.lisp

It's still a proof-of-concept at this stage; I'll post a more complete
version once I finish the rest of the assembler (code layout, labels,
SSE support). Instructions are in the source file, which requires asdf
and cl-iterate.
From: Greg Bacon
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <134h2gr6qg5t057@corp.supernews.com>
After I read PCL's "Practical: Parsing Binary Files" chapter[*], I
used the tools Seibel describes to write a parser for MIL-STD-2045-
47001C, a hairy header format.

[*] http://www.gigamonkeys.com/book/practical-parsing-binary-files.html

As you described, after getting the macros in place, the task was
more-or-less direct transcription of tables from the format's
definition to sexprs. The result was rewarding, especially when I
consider the level of repitition that likely would have resulted
from a less abstract implementation.

It's a sensitive format, but I can poke the (rough) code in AKO if
someone is interested.

Greg
-- 
Ideological decay and confusion are everywhere. But, in this miasma, we
libertarians have that alternative; we have a new and intellectually
stimulating and fascinating ideological paradigm, and one that explains the
collapse of modern statism better than anyone else.  -- Murray Rothbard
From: Frank Goenninger DG1SBG
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <lzfy5y88i6.fsf@pcsde001.de.goenninger.net>
······@hiwaay.net (Greg Bacon) writes:

> After I read PCL's "Practical: Parsing Binary Files" chapter[*], I
> used the tools Seibel describes to write a parser for MIL-STD-2045-
> 47001C, a hairy header format.
>
> It's a sensitive format, but I can poke the (rough) code in AKO if
> someone is interested.

Please do so and announce here. Thx!!!!

Frank
From: Greg Bacon
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <134k5o4lsgau233@corp.supernews.com>
In article <··············@pcsde001.de.goenninger.net>,
    Frank Goenninger DG1SBG  <·············@nomail.org> wrote:

: Please do so and announce here. Thx!!!!

I created a Lisp Programming community site. Let me know if you
have trouble finding it.

Greg
-- 
There is no distinctly American criminal class -- except Congress.
    -- Mark Twain
From: Damien Kick
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <nmp2i.11147$j63.8677@newsread2.news.pas.earthlink.net>
Greg Bacon wrote:
> In article <··············@pcsde001.de.goenninger.net>,
>     Frank Goenninger DG1SBG  <·············@nomail.org> wrote:
> 
> : Please do so and announce here. Thx!!!!
> 
> I created a Lisp Programming community site. Let me know if you
> have trouble finding it.

I'm having trouble finding it.
From: Greg Bacon
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <134m3il5ncmp167@corp.supernews.com>
In article <····················@newsread2.news.pas.earthlink.net>,
    Damien Kick  <·····@earthlink.net> wrote:

: Greg Bacon wrote:
:
: > I created a Lisp Programming community site. Let me know if you
: > have trouble finding it.
:
: I'm having trouble finding it.

Let's debug this via email.

Greg
-- 
When the people find that they can vote themselves money, that will
herald the end of the republic.
    -- Ben Franklin
From: Frank Goenninger DG1SBG
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <lzzm4373sy.fsf@pcsde001.de.goenninger.net>
······@hiwaay.net (Greg Bacon) writes:

> In article <··············@pcsde001.de.goenninger.net>,
>     Frank Goenninger DG1SBG  <·············@nomail.org> wrote:
>
> : Please do so and announce here. Thx!!!!
>
> I created a Lisp Programming community site. Let me know if you
> have trouble finding it.

Ahem - didn't you say that you would post if asked to do so? 
Oh, yeah, and your Lisp Programming community site: No, thanks.
*THE* Lisp programming community site is right here: c.l.l. - That's
just enough for me.

So, no, I won't bite into email exchange. 

Thanks for your help.

Frank
From: Greg Bacon
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <134p6a1d0cod886@corp.supernews.com>
In article <··············@pcsde001.de.goenninger.net>,
    Frank Goenninger DG1SBG  <·············@nomail.org> wrote:

: Ahem - didn't you say that you would post if asked to do so? 

No. I wrote

> It's a sensitive format, but I can poke the (rough) code in AKO if
> someone is interested.

Sorry about the misunderstanding.

Greg
-- 
It is incumbent on every generation to pay its own debts as it goes.  A
principle which if acted on would save one-half the wars of the world.
    -- Thomas Jefferson
From: Frank Goenninger DG1SBG
Subject: Re: Macros are pretty neat...
Date: 
Message-ID: <lzr6pf6yyr.fsf@pcsde001.de.goenninger.net>
······@hiwaay.net (Greg Bacon) writes:

> In article <··············@pcsde001.de.goenninger.net>,
>     Frank Goenninger DG1SBG  <·············@nomail.org> wrote:
>
> : Ahem - didn't you say that you would post if asked to do so? 
>
> No. I wrote
>
>> It's a sensitive format, but I can poke the (rough) code in AKO if
>> someone is interested.
>
> Sorry about the misunderstanding.

Hm - now I have to apologize. Been reading too quick. 
Unfortunately I don't qualify for AKO - if you mean

 https://www.us.army.mil/appiansuite/login/login.fcc

I have been working on classified stuff and am holding an
Enhanced Classification Certificate -  but that's simply not appliable
here ;-)

Since this gets way too complicated for a simple protocol/format I
think we agree to just stop it here ;-)

Thx anyway for announcing it. We now know it's been done somehow by
someone..

Cheers
   Frank