Questions on the Propeller PC compiler, the on chip interpeter, and the encodin
Microcontrolled
Posts: 2,461
I am programming a so-far successful SPIN compiler that runs on a Propeller. My original plan was to have it send all code but the comments to a second Propeller that simulates itself. This, however, could be un-needed since the Propeller has a built-in SPIN interpeter. The question is: How do I compile the code so that it can be read by the SPIN interpeter? I know that I would have to drive the RESn line low and do serial communication to P31 and P30 like the PC does, but how would I send the code? Can you please tell me how this would be accomplished? I do not know PASM, so this may make explaining more difficult. Thank you in advance.
· Micro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
· Micro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
Comments
Do you have any idea what thread this was in? What the title was for example?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
These two lines confuse me. First off you tell us you have a successful SPIN compiler, but then you ask how to compile the code?
I know you are trying to do this for the Propeller design contest, and I know because of this you are being rather secretive, but you need to give us more information. Really!
The *very* simplified process runs something like this :
Take RAW source code text (SPIN & PASM).
Parse the OBJ block(s) allocating space for any sub-objects and enter their names into the symbol table.
Parse the VAR block(s) allocating symbols and relative sizes for every variable, re-ordered from LONG->BYTE to pack tighter.
Assemble the DAT blocks into a single binary BLOB representing all the DAT sections in the file.
Parse the SPIN PUB blocks into raw SPIN bytecode instructions and assemble them into a block. Write block pointer and local variable size into OBJ header at start of object.
Parse the SPIN PRI blocks into raw SPIN bytecode instructions and assemble them into a block. Write block pointer and local variable size into OBJ header at start of object.
Write OBJ pointers into OBJ header at start of object.
Apply shampoo, lather, rinse, repeat for all sub objects.
Lets say you have a single SPIN source file with no other objects in use.
You have a binary block with this structure :
OBJ header / DAT Section / PUB routines / PRI routines / Variables / Stack.
You now need to write the clock speed long, the clock mode byte, the checksum, PBASE, VBASE, DBASE, PCURR, DCURR to the start of the image, then place the object code block immediately after that ($10 for the first spin block).
The header words are these :
PBASE - This points to the start of the object the interpreter runs out of the blocks. It points to the start of the object header.
VBASE - This points to the location of the VAR block variables. It's long aligned and immediately follows the last SPIN object block
DBASE - This points to the location of the STACK. It's long aligned and immediately follows the variables. (which is why if you overflow a VAR array you trample the stack and your program crashes)
PCURR - This points to the current program counter (Initially it should point to the first byte of the first SPIN routine that is to be run after boot)
DCURR - This points to the current stack pointer. (Initially it should point to the third long of the available stack space. The first two are set to $FFF9FFFF. This halts the interpreter if the stack underflows).
Now you have a binary blob the Propeller will be able to do something with, you'd use Chip's Proploader object in the obex to load it into another propeller using /res and P31/P30.
Now, which bit are you having problems with?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lt's not particularly silly, is it?
What I ment, was, I wrote a complicated text editor with New, Open, Save, Export, Delete, etc. functions. I then hooked up the EEPROM (64k) lines of a second prop to the first 2 pins of the first one. I write a program into the upper 32k with Prop 1 and boot the other prop to read it and simulate itself. Well after getting a couple of commands simulated, I thought, "How useless! It has a built in SPIN interpeter that I can use with no programming to the second prop if I can just learn how to communicate with it!" Here I am now, asking questions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
So what you want is the first Prop to emulate an EEPROM so the second prop can load itself from the RAM of the first? That is an interesting approach, but needlessly complicated.
Just leave the eeprom off the second prop altogether and load it over the serial port using Chip's Proploader object.
Inconceivable! "You keep using that word. I do not think it means what you think it means".
Let me try and get this straight.
- You have two propellers.
- One has a text editor on it.
- You plan to use the text editor to develop propeller software on the first propeller, and run it on the second propeller.
Here are my current assumptions. Please feel free to correct me if I'm out of line. :
It's dark. Your current assets include 2 Propellers, A text editor. Your magic lantern only holds approximately 6 weeks of remaining fuel.
Assets remaining on this level :
A 5.25" floppy disk on which resides a compiler
A small jewelery bag containing an external file system to hold data as you compile and link the objects.
An ancient scroll on which is written a means to get any resultant compiled binary from Propeller A to Propeller B.
I'm still a little shady on your phrase "simulate itself". I had the impression you were looking to generate native propeller code, squirt it into a propeller and run it.
Did you know you can load an unmodified propeller binary, perform some simple fixups on the header and run it anywhere in Propeller ram? You could have Propeller B run a little program that accepts a propeller binary over the serial port and then runs it natively. You don't get the full 32k of ram to play with of course, but you can do it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lt's not particularly silly, is it?
The built in SPIN interpreter does not interprete a textual source file. This "Interpreter" is a virtual CPU which executes Bytecode from the HubRAM. This Bytecode must be generated by a Spin compiler (PropTool, BST, Homespun, Sphinx) and this is a very complex process (as BradC has shown you). You can see this Bytecode as another Assembly language optimized for Spin.
Doing the compilation on a Propeller is a big challenge, you need enough memory (SD card, Flash) and must do it in several passes.
But it has be done already by MPark with his Sphinx (see www.sphinxcompiler.com), and he also provides the source code!
What Sphinx misses is a comfortable Editor / IDE, perhaps with syntax highlighting, block copy and so on, that can edit also big files. So if you have written a good Editor, why not adapt it to Sphinx ?
Andy
@BradC: I AM designing it to "simulate itself" BUT I WANT to have it ACTULLY PROGRAM THE SECOND PROPELLER. I just didn't know how to compile a binary file with my editor. Now I think I know, but the descritption that you gave me is very hard to follow if I were to actully apply it to my program. (P.S. What does "parse" mean in the context that you are putting it in?)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
Parse means to read the source file and try to understand what all those statements mean. For example, find out what variable names are used, what function names are there and what instructions ... and convert the string $ffff to a word sized number ... and so on.
As BradC already said: The SPIN interpreter which runs in the propeller does not directly read SPIN-files and can't deal with the text-representation of SPIN. The SPIN which runs in the SPIN interpreter is compiled and linked bytecode. So, they call it interpreter but in fact it is
Have a look at the Sphinx vid ... it'll explain all of that ... hmmm ... - can't find it at parallax homepage ... anyone who has a link?
You can also have a look at http://propeller.wikispaces.com/Spin+Byte+Code·to see what the bytecode that is interpreted looks like.
Post Edited (MagIO2) : 10/13/2009 12:21:17 PM GMT
I know already that it must be compiled into bytecode, I just DON'T KNOW HOW TO DO IT!!! I am starting to get the picture, though. Thanks for the defineing of "parse" by the way.
Now that you have told me the prosess, can you please give me an example of the header of the code? What the clock long long should look like, etc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
Post Edited (microcontrolled) : 10/13/2009 12:07:30 PM GMT
I don't mean to be discouraging but that question tells me you are at the beginning of a very long, but fascinating road.
On the one hand we have the human readable plain text of a program, in Spin in this case. On the other we want to have the binary numbers, or byte codes, that represent the program in such a way that the computer, or in this case the Spin interpreter in the Propeller can execute.
How to get from the text to the byte codes is the process of compilation. A process that has occupied the minds of a great many brilliant people for a long time.
It will require an intimate understanding of the input language, Spin, and an intimate understanding of what the byte codes do. Then you can start on the compiler.
I would recommend reading Jack Crenshaw's series "Let's Build A Compiler" compilers.iecc.com/crenshaw/ for an introduction to the problems and solutions in writing a compiler.
Over the years I have tried to understand various texts on compiler writing, most (all) of them go totally over my head but Jack states the problems in a way I can relate to and shows solutions that can be implemented quite easily.
One of the writers of a Spin compiler here, mpark or BradC I forget who, said he wished he had read Crenshaw before starting.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
You don't know PASM, so are you planning a SPIN compiler without PASM support? You want to program your own SPIN compiler without an idea on what a compiler is doing in detail? And you want this to run on a propeller. Ask BradC. I'd bet that writing a compiler is hard enough without memory limits (running on a PC).
As Sphinx shows it can be done, but to be honest: You should plan your project to be finished for the competition next year if you want to write your own compiler.
Maybe you can focus on the editor you did and the hardware part. Even if you use Sphinx to do the compile/link job you have a lot to do, to put all the pieces together. And my guess is that nobody will blame on you if you create something new and useful this way. That's how this community works. Everybody puts some pieces in and everybody can use those pieces to create something new.
Hippy had posted information a long time ago about the Spin bytecode/object structure. I haven't been able to find the thread again or I would post a link. BradC above also gave a good explanation of the process of compiling (he knows!· He's 'da Man!).
Also, you might want to download HomeSpun and compile a few "known" objects with the -d option to get a listing file and see what it generates.
[noparse][[/noparse]Edit:] See what BradC posted above...his explanation was much more complete.· I missed it the first time I read it [noparse]:([/noparse]
Based on the information I have, the 16 byte header for the entire image would be something like:
long - Frequency
byte - XTAL mode
byte - checksum
word - Pointer to the start of the object
word - Pointer to the start of variables
word - Pointer to the start of the stack
word - Pointer to start of methods(?)
word - Inital stack pointer
(apologies to those more versed in the header than I. Just working off my limited knowledge/best guesses)
Objects themselves have a structure. Again, wish I could find Hippy's documents, as he explains that. Maybe someone else has a link.
Looking at the Sphinx code it may/may not answer questions you have. Certianly I have been looking at that source a lot lately.·
[noparse][[/noparse]Edit:] Also, you might look at Gear, or programs running in Gear.· That is also a good resource.
Post Edited (trodoss) : 10/13/2009 3:23:31 PM GMT
Here's hippy's post with bytecode.txt and mainspec.txt, the two documents that really helped me understand Spin bytecode:
http://forums.parallax.com/showthread.php?p=665019
Good luck with your project!
m
I'm not sure what you mean by "simply editing Sphinx," but if you want to combine your text editor with Sphinx and enter it in the contest, you have my blessing. Although Sphinx is not in the OBEX, it is MIT-licensed so you can use it just like any object from the Exchange.
m
·
Whoever said that I should just take a year to perfect the project and enter it into next years competition, they are forgetting that I cannot. Ken said that this is the last year (due to liability reasons) that anyone under 18 would be allowed to enter the contest. Therefore this is my LAST CHANCE to enter the competition for a long time.....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
Morpheus & Mem+dual Prop SBC w/ 512KB kit $119.95, 2MB memory IO board kit $89.95, both kits $189.95
www.mikronauts.com - my site 6.250MHz custom Crystals for running Propellers at 100MHz
Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
What? Is that for real? What liability reasons? Has the world gone mad?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Good luck Microcontrolled!
...and consider befriending a proxy for next year. I would.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
Safety Tip: Life is as good as YOU think it is!
I am installing Sphinx now, Windows (Vista) says file system is "FAT" but dosn't say 32 or 16. Allocation unit size is 32k, but this is the clusters, not reguarding the format. How do you get FAT16?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
Sphinx does run on the propeller. It also has a simple line editor. As microcontrolled is trying to do, there are lots of files and they need to get copied to an SD card for execution.
This is very sad. What, little Johnny burned his finger with a soldering iron or, worse still, burned a hole in the lounge carpet?
When I was kid we were left alone during lunch breaks at school to use industrial sized lathes and mills in the metal shop. We were casting molten aluminium for fun. Bear in mind that at that time one could leave school on becoming 15.
I'm not suggesting that metalwork is the be all and end all of education but how times have changed. No wonder the western world is struggling to actually make anything.
As my hero Fred Dibnah said "Teaching boys to bake cakes? That's no way to maintain an industrial empire."
en.wikipedia.org/wiki/Fred_Dibnah
So, Micro, I don't know how old you are but for Gods sake don't let all this get to you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Anyway, back to the real topic. If you want to find out more about the Spin Interpreter, look for my faster interpreter thread. Go from back to front looking for the specs attachment. It includes all of hippy's details and updates based on Chip's published interpreter and some extras I found. You can find a link to the thread in the Tools link in my signature below. PS: My latest version has a bug and does not work (got distracted).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade, RetroBlade,·TwinBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
I'm going to modify the start of the program to use a more Windows Explorer type search, instead of using commands it will give a list of files on the SD and when you click on one it goes to an options screen asking what you want to do. Hopefully this will encourage more people to use this wonderful object that can allow for portable programming without the need for a netbook purchase!
@mpark: You have a custom TV text object for the command line part of this program. I cannot figure out how to switch it to normal TV_Text so I can work with it. With what I tried the program crashed when you pushed ENTER, for some reason. What is causing this and what is the point of the variable called at the TV start line?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·
The sxtv object and tv_text are quite different. I don't think it's possible to swap them, at least not easily. I don't know exactly why it crashed because I don't know what you tried, but whatever it was, it was probably doomed from the get-go [noparse]:)[/noparse]
As for the variable at the TV start line, do you mean this line in sphinx.spin: "if term.start( tvPins, SXTVRENDEZVOUS )"? SXTVRENDEZVOUS is not a variable, it is the address of a hub memory location through which the main Sphinx program communicates with the sxtv object.
You might look at the source for ed, the current much-maligned (deservedly so!) Sphinx editor. Ed disables sxtv and uses tvtexted (which is mostly compatible with tv_text) for its display.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
But you·can·call me micro.
Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·