home .. forth .. colorforth mail list archive ..

Re: [colorforth] OkadWork.cf disassembled


On Wed, Mar 04, 2009 at 04:03:03PM -0700, John Comeau wrote:
> For those of you itching to get a native-booting version of
> OkadWork.cf, and haven't been able to make a disassembly that reliably
> reassembles back to the boot code of OkadWork, check out
> http://unternet.net/cf2/. I'm not sure I got the non-code sections all
> separated out, but I've verified that the disassembly made with
> Albert's cidis compiles to an identical binary (.bin vs .cfboot) using
> cias. So as long as you change code in such a way as not to mess up
> any offsets, by making your changes fit the same space as the original
> code (check with cmp -l, as in the Makefile), you can test different
> video modes and such. Thanks to Albert van der Horst for the new
> release of ciasdis!
>

Maybe I should elaborate a bit more about how I disassembled colorforth.
(It is based on a table driven Forth assembler using my PostIt FixUp
principle. The tables are reused to disassemble).

I had added a special disassembler for the table ForthHuff.
It takes a 32-bit cell, interpret it as a colorword string.
Then reassemblable code is to be read as
  ( lay down longs: ) dl  ( Get a string: )       S" boot"
( "boot" is ciforth idiom)
      ( adr len -- cw ) (convert it to a colorword.) >CN

The ForthXT must be analysed in parallel.
It contains execution addresses, and they are added as labels with names
derived from the colornames.

A third thing is done. The execution addresses are executable code.
So we can "crawl" from that address until an unconditional transfer is
done (jump or return).

So this is how it looked, a long time ago.

colorcm-1.41.dis

( 0000,09E0 )   :ForthHuff   dl "boot" >CN "warm" >CN "pause" >CN "macro" >CN
( 0000,09F0 )                 dl "forth" >CN "c" >CN "stop" >CN "read" >CN
( 0000,0A00 )                 dl "write" >CN "nc" >CN "comman" >CN "seek" >CN

...

( 0000,14E4 )   :ForthXT   dl X_boot X_warm X_pause X_macro
(                           0,1DD0 L, ......)
( 0000,14F4 )                 dl X_forth X_c X_stop X_read
( 0000,1504 )                 dl X_write X_nc X_comman X_seek

...

( 0000,1DD0 )   :X_boot    MOVI|B, AL| L0000,00F6 8 + IB,
( 0000,1DD2 )                  OUT|P, B'| #CHARS 4 + P,
( 0000,1DD4 )   :L0000,1DD4    JMPS, L0000,1DD4 RB,
( 0000,1DD6 )   :X_erase    MOV, X| T| CX'| R| AX|
( 0000,1DD8 )                  SHLI, X| R| CX| 8 IS,
( 0000,1DDB )                  LODS, X'|
( 0000,1DDC )                  PUSH|X, DI|
( 0000,1DDD )                  MOV, X| T| DI'| R| AX|
( 0000,1DDF )                  SHLI, X| R| DI| 0A IS,
( 0000,1DE2 )                  XOR, X| T| AX'| R| AX|
( 0000,1DE4 )                  REPZ,
( 0000,1DE5 )                  STOS, X'|
( 0000,1DE6 )                  POP|X, DI|
( 0000,1DE7 )                  LODS, X'|
( 0000,1DE8 )                  RET,


Now in colorcm-1.58.dis the disassembly is more advanced and the casual
observer may think that both tables have disappeared because they are no
no longer apparent in the disassembly.
Instead the tables are generated as separate sections.

This is done by the word : HEADER .

\ Forth header for "name".
\ Add execution address and colorname to appropriate segments.^H^H^Hsection.
: HEADER   _AP_ ForthXT: AS-,   (WORD) >CN ForthHuff: AS-,   DEFAULT: ;

...

HEADER boot
( 0000,1DD0 )   :X_boot    MOVI|B, AL| -2 IB,
( 0000,1DD2 )                  OUT|P, B'| +64 P,
( 0000,1DD4 )   :L0000,1DD4    JMPS, L0000,1DD4 RB,

...

HEADER erase
( 0000,1DD6 )   :X_erase    MOV, X| T| CX'| R| AX|
( 0000,1DD8 )                  SHLI, X| R| CX| +8 IS,
( 0000,1DDB )                  LODS, X'|
( 0000,1DDC )                  PUSH|X, DI|


HEADER is to be read as follows:

Get the current code pointer
switch to the execution table (a section)
Comma the address into that assembler section

Get a name from the input stream
Make it into a Hufman name
switch to the Huffman table (a section)
Comma the H-name into that assembler section

Switch back to the default (code) section.

o-O-o

It is clear that it now becomes impossible to have the
parallel tables misaligned. Furthermore the code can
be rearranged with impunity.

(With a    2DUP _AP_ LABELED   I could have eliminated
even the  :X_boot   labels, but it is not clear whether
that would be an improvement. One might want to look for
:X_boot to find where the label is defined.)


--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com