Wednesday, March 26, 2008

ImageCraft and AS430 Library Formats for the MSP430

by Travis Goodspeed <travis at utk.edu>
at the Extreme Measurement Communications Center
of the Oak Ridge National Laboratory

I've been playing with various MSP430 compilers lately in an attempt to add import macros to msp430static. GNU's objdump makes this trivially easy for mspgcc, but I haven't been so lucky with the other compilers. One exception is ImageCraft's compiler, whose library format is beautifully manageable. This short article will discuss that format, with sufficient depth that a decoder or encoder script may be written. I will also discuss another tool, the AS430 assembler, which uses a similar file format.

A free 4kb version is available at http://www.imagecraft.com/. It works perfectly in Linux, just run `wine iccv7430_demo.exe', installing it to /opt/iccv7430/. Once installed, the IDE can be launched by `wine /opt/iccv7430/bin/icc430ide.exe'.

The following image shows the opening lines of libc.a, which is in a relocatable object format similar to that of the AS430 linker's.

You can find a description of the linking format, here.

The S-line tells us that the object's symbol name is _abs. The T-line contains the object code, "00 00 0e 93 03 34 3e e0 ff ff 1e 53 30 41". This R-line specifies no relocation.

The code, which begins at the third byte of the T-line, disassembles to the following in word-wise notation:
0x930E cmp #0, r14
0x3403 jge +8
0xE03E XOR #0xFFFF,r14
0xFFFF
0x531E add #1, r14
0x4130 ret

Quite obviously, this inverts and adds 1 to r14 if its value is less than 0. In C,
int _abs(int x){
if(x<0)
return -x;
else
return x;
}
It's worth noting that r14 can be inverted with a single word, 0xE33E, rather than the two used here by use of the constant generator. That is exactly what GCC does:
   0:   0f 93           cmp     #0,     r15     ;r3 As==00
2: 02 34 jge $+6 ;abs 0x8
4: 3f e3 inv r15 ;
6: 1f 53 inc r15 ;
8: 30 41 ret
Getting back to the format at hand, AS430 may be downloaded here. Go for the latter link, as it's direct and doesn't require that you run Simtel's win32 downloader application.

Once downloaded, Linux users should install by use of the following commands:
karen% sudo ln -s `pwd`/ASXMAK/LINUX/EXE/AS430 /usr/local/bin/as430
karen% sudo chmod +x ASXMAK/LINUX/EXE/*
karen%
Moving the T430.ASM example to T430.asm, calling "as430 -o T430" creates T430.rel, in the same relocatable object format used above. It's rather inconvenient that the tool is case-sensitive and windows-oriented, but it works well in Linux once you recognize its difficulty with case-sensitive filesystems.

Object division is different in ImageCraft. Note the ^M entries in the screenshot, which in emacs denote a CR. The entries only exist between the .begin/.end macros, suggesting that the file was produced with more than one tool. This makes sense: one tool is the archiver, while the other is the assembler. The archiver uses LF, as in Unix textfiles, while the assembler uses CRLF, as in DOS textfiles.

Just to be sure this would ship in production code, I used abs() in an example project and found the following in the output ihex:
:14F064000495FD3B30410E9303343EE0FFFF1E53304130410
'3EE0FFFF' is the little-endian equivalent of '0xE03E 0xFFFF' above.

Some other formats, all of them ASCII, deserve mention here. The first being the debug format, which is built into PROJECT.dbg by the IDE.
IMAGECRAFT DEBUG FORMAT
VERSION 1.2
CPU MSP430
FRAMEPOINTER R1
DIR z:\home\travis\tmp\icc\
FILE foo.c
FUNC main F052 fV
BLOCK 3 F052
DEFREG x 5 I
DEFREG y 4 I
LINE 3 F052
LINE 4 F052
LINE 5 F05E
LINE 6 F060
LINE 6 F062
LINE 6 F062
LINE 6 F064
BLOCKEND 0 F068
FUNCEND F068
FILE foo.s
LINE 16 F052
LINE 17 F056
LINE 18 F05A
LINE 19 F05C
LINE 22 F05E
LINE 25 F060
LINE 30 F062
LINE 33 F064
LINE 34 F066
LINE 38 F068
START F000
This is easy enough to read. FILE defines a source file, FUNC defines a function, BLOCK defines a region of code, DEFREG defines which register a variable is contained within, and LINE denotes the address to which a particular line has been compiled.

PROJECT.lst contains annotated machine code. PROJECT.mp describes memory areas and linking information.

PROJECT.mak is a makefile. Building from the command-line works perfectly with the proper environment variables, but without them the unregistered version will refuse to run outside of the IDE.
karen% wine /opt/iccv7430/bin/imakew.exe -f FOO.mak 
icc430 -c -IC:\icc\include\ -e -D__ICC_VERSION="V7.06A" -DF148 -l -g -Wf-hwmult -Wa-g z:\home\travis\tmp\icc\foo.c
icc430 -o FOO -LC:\icc\lib\ -g -blit:0xF000.0xFFDF -bdata:0x0200.0x0A00 -dram_end:0x0A00 -fintelhex -binfo:0x1000 @FOO.lk
Device 3% full.
karen%
I like the ASCII nature of the compiler's file formats, which makes them very easy to parse. For this reason, the compiler was the first after GCC to be supported in msp430static.

3 comments:

Jim Rhodes said...

I will read more about these formats now. But you should check this https://writemypaper4me.org/blog/research-papers-writing service first of all. You will like it.

Unknown said...

El kit contiene:
1 camiseta de manga corta
1 breve
1 par de calcetines
1 toalla

Embalaje: 40 kits / caja
Tamaño: XXL
Precio: Euro 2,00 / Kit "Kit de ropa interior de algodón de verano con amianto
"

David Abraham said...


Additionally, you can read this blog to get a lot of helpful information. You can get assistance from the history dissertation examples service if you need to understand how to make an assignment it is an amusing website I will come here again.