Shop OBEX P1 Docs P2 Docs Learn Events
What's in the first 16 bytes of the compiled binary ("initialization data")? — Parallax Forums

What's in the first 16 bytes of the compiled binary ("initialization data")?

Keith LeinenbachKeith Leinenbach Posts: 25
edited 2012-01-25 10:56 in Propeller 1
What's in the first 16 bytes of the compiled binary ("initialization data")? The first 8 bytes are defined as CLKFREQ and CLKMODE, but what are the last 8?

I am curious because I wanted to know how to separate the program length from the variable length in a binary image. The Propeller Tool can differentiate these values with only a loaded binary with no code listing.

I thought it might be in the last 8 bytes, but it doesn't seem to match up.

Thanks!
Keith

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2012-01-25 08:41
    The first 16 bytes are defined as follows:
    hub addr content
    -------- -------
    $0 to $3 clkfreq
    $4       clkmode
    $5       checksum
    $6 to $7 pbase - Address of the top object. Always $10
    $8 to $9 vbase - Start of VAR data.  Equal to the file size
    $A to $B dbase - Start of the stack.  Equal to the program size
    $C to $D pcurr - Execution start address
    $E to $F dcurr - Initial value of the stack pointer
    
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2012-01-25 09:13
    Just one minor thing to add:
    vbase (start of VAR data) is only equal to the file size in *.binary files. For *.eeprom files, which are always 32k, it's not.

    Roy
  • Keith LeinenbachKeith Leinenbach Posts: 25
    edited 2012-01-25 09:26
    Thank you Dave. What are the last 8 bytes after the code and VAR section and is this always 8 bytes? Also, is there a handy dandy reference for information like this or did I just miss it in the docs?

    Oops on CLKMODE, only 1 byte!

    Keith
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-01-25 10:36
    The last 8 bytes that are shown in the HEX display of the Prop tool are the first 8 bytes that are put on the stack when a program is loaded. The value of the 8 bytes is FF FF F9 FF FF FF F9 FF, which represent a stack frame used when calling methods. The stack frame contains the return address, which is FFF9 in this case. This is used when a program aborts or returns from the first method. FFF9 is located in the ROM, and it contains a few bytecodes that stop the current cog.

    These 8 bytes aren't included in a binary file, and they are added when the program is loaded to the Prop. If you add the bytes in a binary file you will get a sum of $14. If you add the 8 extra bytes to this you will get zero, so the checksum at location $0006 includes the extra bytes. The values of DCURR and DBASE normally differ by 8 due to the 8 extra bytes.

    This information is not in the official Parallax documents. There is no single document with the details about how Spin operates, but you can find quite a bit of information at http://propeller.wikispaces.com/ .
  • Keith LeinenbachKeith Leinenbach Posts: 25
    edited 2012-01-25 10:56
    Thanks Roy and Dave. Valuable information.

    Keith
Sign In or Register to comment.