Shop OBEX P1 Docs P2 Docs Learn Events
the Propeller Emulator — Parallax Forums

the Propeller Emulator

Chris MicroChris Micro Posts: 160
edited 2009-07-16 14:08 in Propeller 1
Propeller Emulator
==================


This programm runs propeller code on a pc.
It looks for a file "test.binary". If this is a assembler file,
it should contain the magic number as described below.

V048B:
- windows console
- linux console
- 4 cogs
- 32K hub memory
- dissassembler
- debugger
- speed/cog~3Mips@1.6Hz intel ATOM processor

console commands to start the emulator:

windows: propsim.exe

linux: ./propsim.out

The linux console has the advantage that you can use cursor positoning commands
and color commants like in vga_text.spin.
This is due to the linux console supports escape sequences for an Ansi-Terminal.
The windows console does not support this, so there is only mono color and
no cursor postioning.

option examples

./propsim -h -> help, show options
./propsim -d -> run in debug mode, press 'h'<ret> for help
./propsim -d -a -> run in debug mode and don't try to load and execute spin.binary

Assembler file:
===============
An assembler file which can run on the emulator should have the following start up
sequence with a magic number.

pub xx
  'nothing
DAT
magicNumber
       long    $55AA1133   'magic number as starting point for the cog emulator

        org     0
start
    ' some example code     
        movs printText,#hello
        call #printText
    ....
    ....    

    fit 496






the code for the emulator can be found here

Post Edited (Chris Micro) : 7/13/2009 9:16:00 AM GMT
«134

Comments

  • CassLanCassLan Posts: 586
    edited 2009-07-04 15:08
    Hey Chris I can't wait to try it out!
    Any plans for object/peripheral emulation? Like TV_Text

    Rick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Prop Forum Search (Via Google)
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-04 15:12
    TV_Text is emulated in the following sense:

    the characters you write to hub memory 0 by wrbyte are displayed.

    You can see how it works in the test.spin file.

    You can change colors and position the cursor like you do it in TV_Text.
  • jazzedjazzed Posts: 11,803
    edited 2009-07-04 15:21
    Have you tried running Propeller ROM code? ... booter.spin, interpreter.spin, runner.spin

    I ran your app on my linux server account and it looks fine. A windows version could be useful
    for me since the linux server is not mine (I don't have root privileges).

    I see you use the -d argument for debug. Are there interactive commands other than "enter" ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230

    Post Edited (jazzed) : 7/4/2009 3:32:08 PM GMT
  • AleAle Posts: 2,363
    edited 2009-07-04 15:29
    The spin interpreter needs compiling. If you just compile it it will work as it is (with PropTool) if you remove the header, or use this compiled version. I'm using it in pPropellerSim for the Spin interpreter.
    Edit: Mac OS adds some silly files that start with a dot, you can remove them from the zip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit the home of pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • jazzedjazzed Posts: 11,803
    edited 2009-07-04 15:33
    Ale, are you able to fully boot a Propeller in pPropellerSim ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • AleAle Posts: 2,363
    edited 2009-07-04 16:27
    jazzed:
    In short: No.
    Long: I never ran the booting code. It should work if I emulate a i2c eeprom smile.gif. The spin interpreter is loaded using the normal HUB reading cycle and Spin is interpreted using it. So a normal Spin program runs and you can spawn new cogs using COGINIT.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit the home of pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-04 19:43
    Hi Ale,

    thank you for posting the code.
    The spin interpreter has to be called with the register PAR preloaded ( I assume it is the beginning of the propeller program ).
    Which is the address I have to preload PAR?

    best regards,
    chris
  • AleAle Posts: 2,363
    edited 2009-07-04 20:06
    At least for the first one it has to be the number 4.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit the home of pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-04 20:10
    Thanks, thats what I needed. smile.gif
    I will try to run it tomorrow.
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-05 11:11
    Hi all,

    I posted the new version V048 which loads the file

    spin.binary

    which is the spin interpreter.
    If the file is found, the code will be loaded in COG0 and the cog is started with PAR=4.
    I have no experience with the interpreter and it seems that there is some error.

    You can debug the interpreter by starting the program with the -d option

    ./propsim.out -d

    pressing return ... will single step through the code.
    If you press 'h'<return> you will get a list of the commands in the debugger.

    Can someone take a short look into the trace to help me find the error?
    This would be very nice,

    chris
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-05 14:43
    Hi there, the first windows version is running,
    Any remarks welcome ...
  • jazzedjazzed Posts: 11,803
    edited 2009-07-05 14:51
    Can you add "spin.binary" to your package or tell how you're building it? File interpreter.spin does not have a pub and will not compile.
    Thanks for the h command and the windows cmd version. Any reason you are limiting to 4 COGs ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-05 15:07
    Ale posted the code in this thread. He named it spin.pasm.bin . You can rename it and use it.
    I'm not sure about legal issues, if I would pack the spin code in the zip file. I'm sure that very soon someone from Parallax will comment this in this thread.

    >Any reason you are limiting to 4 COGs ?
    Only because every COG needs processing time. I estimate that the speed with 4 COGs is about 3Mips/cog on my ATOM 1.6GHz ( yes it is only a NetBook smile.gif )

    Could you run the emulator with the example code and tell me how fast it is?

    It would be very interesting if someone could write a little assembler benchmark program to see the mean speed of the emulator.
  • SapiehaSapieha Posts: 2,964
    edited 2009-07-05 15:36
    Hi Chris Micro.

    I'm very interested in Yours Emulator BUT in litle other approach.
    No mater if it will be speed isues BUT nessesary it is fuly compatible with Propeller chip.

    My question is If it then be posible to adopt this emulator to THAT Simulation program.
    http://www.labcenter.co.uk/products/vsm_overview.cfm

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha
  • jazzedjazzed Posts: 11,803
    edited 2009-07-05 15:36
    Not sure what you mean, but waitcnt appears to be working although your implementation could use a little tweek.
            mov timer, delay
            add timer, cnt
    numberLoop
            waitcnt timer,delay
            movs printText,#text
            call #printText
            jmp #numberLoop
    
    


    Benchmark is a loaded word around here [noparse]:)[/noparse] I might do some low complexity testing later, but can't promise much today ... we'll see.

    I was able to start ALE's file and step through it. I suspect that you need to make a loader for normal spin programs.
    Having a -spin <spinfile> agrument and using Propellent to compile would be greatly appreciated.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-05 19:33
    > ... your implementation could use a little tweek.
    Yes, thank you, I was a little lazy in preloading the timer variable with the cnt value. smile.gif

    >I suspect that you need to make a loader for normal spin programs.
    The "test.spin" file is loaded into the hub memory. I assumed, that the spin interpreter running in COG0 automatically interprets "test.spin" as spin code.

    Do you have any useful ideas what should be implemented in the emulator?
    I was thinking of laying the keyboard as input on $f002 in the main memory.
    Another thing is I want to create sound. But it seems the best if the emulator can write some values in a wav-file.
  • jazzedjazzed Posts: 11,803
    edited 2009-07-06 01:09
    Being able to start the interpreter is not of much value unless you can demonstrate in some way that it is functioning [noparse]:)[/noparse]

    One of the most impressive Propeller Emulator things I've seen (but not run myself) is the TV display produced by running GEAR. Being able to create virtual peripherals for TV, SEEPROM, audio, or other devices without having to change the emulator has value. For me I hope it would be like plugging in a propeller proto-board to my PC and doing work that can easily transfer to real hardware.

    Getting a "simulator" to behave exactly like real hardware without connecting anything to the workstation or PC, from compiling and downloading from the propeller tool to running code with the luxury of breaking the main cog execution would be premium. If one could get a virtual COM port to enumerate on the PC (linux driver would be easier[noparse]:)[/noparse], that would enable virtual downloads. One could create a "memory mapped" TV/VGA display pretty easily on a PC window (I've never tried graphics on linux). Emulating a SEEPROM would not be too hard and I've actually started writing code for that and a larger system that could potentially connect emulated components together.

    I guess the question is: "how useful would all of that be?"

    When I'm done with my current distraction, I could help you with some of this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-06 18:05
    Sapieha said...
    My question is If it then be posible to adopt this emulator to THAT Simulation program.
    http://www.labcenter.co.uk/products/vsm_overview.cfm

    Uhh, that would be hard. I tried to concentrate on the logical structure of the commands not so much on the accurate timing relations.
    In the emulator, every command takes exactly one cycle and also every hub access takes exactly one cycle. This is different to the real propeller and also the peripherals are not emulated yet.
    I would not say that it is impossible, but it would take really a lot of time to program this. Because it is only a hobby project for me I would not invest that much time in it unless someone pays me for that.
    jazzed said...

    One of the most impressive Propeller Emulator things I've seen (but not run myself) is the TV display produced by running GEAR.
    ....
    When I'm done with my current distraction, I could help you with some of this.

    Interesting, I saw it, tried it and nothing worked. So I thought it is a dead project.

    I began this emulator project, because I did another little project where I wanted to see how difficult it is to write a simple emulator.

    Than I thought, the propeller instructions are much more powerful than these of the Lapoco-core and will try to implement an emulator for the propeller.
    In the early version I ran it on the Atmega32 ( where the memory is to small to run spin ) and afterwards I ran it on an LPC2103 ARM 7 processor.
    If spin would be running in the emulator it would be interesting to run it on the ARM7 burger.gif
    ( just for fun, because it will be slow )

    I would be very glad if you are interested in this project and like to work with me on it. I will than make it Open Source.

    Post Edited (Chris Micro) : 7/6/2009 6:10:51 PM GMT
  • jazzedjazzed Posts: 11,803
    edited 2009-07-07 05:49
    Chris Micro said...
    I would be very glad if you are interested in this project and like to work with me on it ....
    I'll work with you on making the emulator run Spin programs on Windows and Linux PCs after I finish the COBY DP151 hack. It might be interesting to port the Spin interpreter to another uC and allow interface to another chip's native ASM, but I don't really care to contribute to PASM running emulated on another chip other than the PC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-07 07:11
    Just want to announce that I'm currently writing a Propeller simulator as well. (In fact I started after I read this thread ;o) My version is written in Java, so it will run on any system with a Java-VM available.

    I do simulate the whole COG pipeline, so self modifying code has the same restrictions as on the real prop.
    Current status is that I load the RAM and ROM (from eeprom-files - don't see a reason for running the boot-loader at the moment) and I start COG 0 with the SPIN interpreter.
    The HUB is already doing it's job, so rd / wr are synchronized with the access window.
    Actually it's doin nothing but disassembling what it finds in COG-RAM, because next step is to implement the instructions.

    Just want to tell you. I do it for the pure interest, so I'll continue anyway. So, if you have anything better to do you might prefere to wait.

    Post Edited (MagIO2) : 7/7/2009 7:27:26 AM GMT
  • AleAle Posts: 2,363
    edited 2009-07-07 09:02
    Hei MagIO2: Why you just not extend/improve the one I wrote, also in Java ? It only needs a spin disassembler and some small touches here and there ?

    Edit: I'll post the code as soon as I can post it :-(, sadly it failed 4 time to upload here rolleyes.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit the home of pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU

    Post Edited (Ale) : 7/7/2009 2:14:53 PM GMT
  • Ron SutcliffeRon Sutcliffe Posts: 420
    edited 2009-07-07 09:57
    It would be fantastic if there where a Prop emulator, with virtual TV and KB interface.

    An emulator that could boot, load the spin interpreter into cog 0 and load user code from *user.binary*,··
    would be very useful
    It does,·so lets have another play

    Having a virtual Tv.obj with access to the standard tv parameters and memory map Users could load their own version of TV_text or TV_graphics.

    Not having to pull out the PDB, screen and PSU’s every time you want to work on something would be really handy. I do use my own version of tv_text often for tracking pointers, debugging and the like and am sure many other do the same.

    A virtual com ports would allow users to adopt their own keyboard code or use PST, realterm etc.

    Neat.

    Ron

    Post Edited (Ron Sutcliffe) : 7/7/2009 10:54:33 AM GMT
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-07 13:05
    Don't see a big problem with a virtual display. Actually that's one of my goals. The good thing here is that in the end the output is generated by hardware, the video generator. To simulate the propeller means to simulate the video-generator as well. So, besides driving the virtual pins the simulator can simply generate an image to be displayed.

    The keyboard/mouse/serial interface ... is done in software. Currently I don't know how fast the simulator will be in terms of MIPS/COG. Plus, the real execution time per instruction is most likely different for different instructions. So, attaching these virtual pins to some real hardware will be difficult because you can't guarantee the proper timing without a lot of work. Simulating the hardware means a lot of work as well - but could maybe be done by the community.
    But maybe it would be easier to have a driver-replacement. For example the driver replacement of the keyboard driver has the same interface for SPIN/PASM but is not really attached to I/O pins. Instead the PCs keyboard input is read. Easy way to inject data into the COG would be to use the not used opcodes which have been reserved for future use.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-07 13:10
    @Ale: As I said "I do it for the pure interest".

    And to be honest ... I think it's easier to do this by myself from scratch than reading tons of code and modify that. Do you already simulate the counters and the video-generator? Did not find this in your COG-class on the first glance.

    SPIN disassembler seems to be a bit trickier, isn't it? Because that's compiled into bytecode and the bytecode is not a 1 to 1 relation to SPIN instructions, or is it?
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-07 13:22
    Ale's Propeller Simulator was very useful to me to learn Spin Assembler. You could easily modify the code and debug through it.

    It was available under

    http://sourceforge.net/projects/propellersim
  • AleAle Posts: 2,363
    edited 2009-07-07 14:15
    MagIO2: I do not simulate counters or video circuitry. It was not the idea of the sim. The problem with Spin is not exactly Spin, it is how the different things are put together. As soon as I understand it I can implement it, it did not happen till now though. lol.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit the home of pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • BradCBradC Posts: 2,601
    edited 2009-07-07 15:05
    MagIO2 said...

    SPIN disassembler seems to be a bit trickier, isn't it? Because that's compiled into bytecode and the bytecode is not a 1 to 1 relation to SPIN instructions, or is it?

    Yes and no. I wrote a spin disassembler in a night with the Interpreter code as a reference. It's not difficult. This would get you to a bytecode listing you could single-step through.

    To disassemble back to a structure resembling original source is a bit harder. Case statements are doable, If/Else is a bit harder and repeat gets a bit complex.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Missed it by ->" "<- that much!
  • jazzedjazzed Posts: 11,803
    edited 2009-07-07 15:34
    @Ron, Yes indeed, a virtual COM port so we can just download to the model would be cool [noparse]:)[/noparse] I wonder if CounterRotatingProps knows how to make one of those for windows. Like I said linux is pretty easy IF you have root access ... I wrote drivers for 2.4/2.6 kernel before.

    Clock ticks similar to Verilog in an emulation / simulation model is necessary especially for counters. I actually started designing a software "platform" that would use device model libraries, pin-outs, and net-lists that would run based on ticks. An SEEPROM model would be one of the first implemented followed by a Propeller model (except that I'm distracted by hacking the COBY DP151). Here is a list of files and some "config" samples.

    Makefile     config     e.exe      /hashtable  netlist.h      propeller.h  seep.c
    arraylist.c  devices.c  emulator.c  main.c     propeller.c    proper       seep.dev
    arraylist.h  devices.h  emulator.h  netlist.c  propeller.dev  prophw.h     seep.h
    
    


    Example .dev and config files are attached.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230

    Post Edited (jazzed) : 7/8/2009 3:57:51 PM GMT
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-07 19:21
    jazzed said...

    Clock ticks similar to Verilog in an emulation / simulation model is necessary especially for counters

    uiii, that looks like a lot of work. This looks really professional. At the moment try to correct some errors in the emulator.
    Probably you could try to run some assembler commands ( or a little program ) on the emulator to see if it is all working ok.
    BradC said...
    Case statements are doable, If/Else is a bit harder and repeat gets a bit complex.
    Hi Brad, there is exactly my problem: The emulator is now able to run some spin
    ( which means something easy like outa := 1 .. waitcnt .. and so on ). But wiht the if/Else and repeat instructions there is a problem. It simply ignores them.

    Could you run the emulator with

    ./propsim.out -d

    With <ret> there is a single step mode ( and h for help ). Probably you can see in a few steps where it goes the wrong way.

    Best regards,
    chris

    Post Edited (Chris Micro) : 7/8/2009 7:24:26 AM GMT
  • BradCBradC Posts: 2,601
    edited 2009-07-08 01:45
    Wow, that is hard to follow [noparse]:)[/noparse]

    A completely unrelated point, but you are not decoding the lock instructions

    cog0 - 0091 : 5CCBBDDA IF_NC_AND_Z  CALL     1DE ,#1DA [noparse][[/noparse]dest]5C7C00F8 [noparse][[/noparse]source]84FFDE04  Z: 0  C: 1 
    
    cog0 - 0092 : 0C480000 IF_NC_AND_Z  -------- 000 ,#000 nr [noparse][[/noparse]dest]00000000 [noparse][[/noparse]source]00000000  Z: 0  C: 1  <---- lockret
    
    cog0 - 0093 : 08480200 IF_NC_AND_Z  WRLONG  001 ,#000 nr [noparse][[/noparse]dest]00001170 [noparse][[/noparse]source]00000000  Z: 0  C: 1 
    
    




    You have some uninitialised memory, or you are writing something somewhere it's not supposed to go.

    This code is supposed to write $AA to OUTA, but 50% of the time I run it, it writes $55.

    The non-deterministic nature of the fault indicates a bug that is not a logic error, but something more sinister.

    I can't really help much further until I can get the same result each time I run the simulator [noparse];)[/noparse]

    Local Parameter DBASE:0000 - Result
    Local Variable  DBASE:0004 - x
    Local Variable  DBASE:0008 - y
    |===========================================================================|
    2                        if 1 == 2
    Addr : 0018:             36  : Constant 2 $00000001
    Addr : 0019:          37 00  : Constant Mask Y=0 00000002
    Addr : 001B:             FC  : Math Op ==    
    Addr : 001C: JZ Label0002
    Addr : 001C:          0A 06  : jz Address = 0024 6
    3                          outa := $55
    Addr : 001E:          38 55  : Constant 1 Bytes - 55 
    Addr : 0020:          3F B4  : Register op OUTA Write
    Addr : 0022: JMP Label0003
    Addr : 0022:          04 04  : Jmp 0028 4    
    Addr : 0024: Label0002
    5                          outa := $AA
    Addr : 0024:          38 AA  : Constant 1 Bytes - AA 
    Addr : 0026:          3F B4  : Register op OUTA Write
    Addr : 0028: Label0004
    Addr : 0028: Label0003
    Addr : 0028:             32  : Return        
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Missed it by ->" "<- that much!
Sign In or Register to comment.