Shop OBEX P1 Docs P2 Docs Learn Events
DOL - Dynamic Object Loader — Parallax Forums

DOL - Dynamic Object Loader

stevenmess2004stevenmess2004 Posts: 1,102
edited 2011-03-30 06:13 in Propeller 1
DOL is now successfully loading an object from an SD card and running it!!! So I thought that I would start a thread for it.

I will keep this post updated with the latest version.

New beta version of DOL2, haven't updated version number since basically nothing in DOL itself has changed, just the demo that comes with it. Much improved but its not finished yet. Dump all the *.dol files onto your sd card. TV needs to be on pins 12+, keyboard on 26+ and sd on 0-3. I'll update it to include the spec soon smile.gif. Then load SDM_DOL2_Core_V001. You should get a Hello world message. Then type in "upper" and after a short period of time the screen will stop displaying new stuff. This loads the file upper.dol and gives it access to standard input, output and error streams. If you type on the keyboard you will see the stuff converted to uppercase (but don't try anything other than lowercase letters, it just adds on "A"-"a"). You will also find a file in the zip that has a basic object tree that I've been working on. All the stuff below is old but I'll leave it here at least until I get this version finished.

DOL can
- dynamically load objects from an SD card (reasonably tested)
- dynamically unload loaded objects from memory (reasonably tested)
- allow loaded objects to call other loaded objects (reasonably tested)
- give access to system functions such as
--file access (reasonably tested)
--heap access (reasonably tested)

Current version V_014
-Should be able to be used.
-Requires an SD. You need a TV and mouse for the demo.
-See DOL readme in zip file for instructions.
-Loads a file from the SD card and displays "Hello World!" on the TV demonstrating loading a TV driver and running it.
-Converted the mouse driver. Not all of the methods are callable but there should be enough to be useful.

Issues
-Setting freed memory to zero was causing an error so it is now commented out. I'll try to fix it for the next version.

Next version
-More testing.
-Maybe a keyboard and mouse driver.

Thanks to
-hippy for all his work on spin op-code and object format
-Mike Green for modified version of fsrw
-Peter for his heap object
-Chip for making such a great chip


Steven

Post Edited (stevenmess2004) : 7/11/2008 1:21:57 PM GMT
«1

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-01-14 12:15
    Steven,
    Is it possible to use a hash function for the object/method names instead of constants?
    We could then use
    callobject(hash(string("objectname")),hash(string("methodname")),arg1,arg2)
    Here are some·hashfunctions
    http://www.cse.yorku.ca/~oz/hash.html

    methodRunner case would change to
    · case methodname
    ··· hash(string("init")):
    ··· hash(string("run")):
    ··· hash(string("stop")):

    For objectname you can of cource use the filename.
    That really should improve readability (and solve maintenance issues).

    regards peter
  • hippyhippy Posts: 1,981
    edited 2008-01-14 13:06
    I think some hash encoding is a good idea. Just packing the first four characters into a long would be a start, 5-bit characters would allow six character names, proper hashing even better.

    The only downside is that it adds a lot of run-time overhead doing the hashing on every call and throughout that case statement every time. Ideally a built-in string hashing function for the PropTool is needed here, or macro support, so it can be done at compile time.

    It might be possible to do a JIT hashing to speed things up. The string pointed to has the first msb clear if it is character data ( assuming ASCII characters =< $7F ), and the bytes in bytecode could be turned into a hash and written back with msb set. Care would have to be taken with strings less than three characters and the hash wouldn't be long aligned, so there may still need to be a fair amount of bit shifting.

    Added : Or change PropTool so every string is only ever generated once. Then the address of the string is its hash. I can think of a few possible cases where that would be undesirable, and in those it can be worked round. - Won't work because the loadable object has its own strings and will not be the same as the loader does. Oh well.

    Post Edited (hippy) : 1/14/2008 1:17:04 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-01-14 13:38
    A lot of the overhead can be moved to loadObject, which already takes
    quite some time to load an object. The objectname can be converted
    to a hashnumber, that hashnumber loaded into a free entry of objectNameList[noparse]/noparse,
    and if object present on SD and enough·memory and a free entry available,
    loadObject can return the entry number 1-16 (handle) or null (object not loaded).
    The handle can be passed to callObject, making the search for the entry
    obsolete which saves time. That handle would also be passed to unloadObject,
    again eliminating·a search.
    Edit: in fact, objectNameList[noparse]/noparse can be eliminated alltogether, as objectStartPtr[noparse]/noparse
    holds a nonzero value for a loaded object, or null for a free entry.

    regards peter

    Post Edited (Peter Verkaik) : 1/14/2008 1:52:25 PM GMT
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-15 06:03
    There is probably quite a few places where I could speed things up and save memory. I probably don't need the objectAllocated variable either. Just check the objectStartPtr[noparse]/noparse for 0 will tell us if the object is allocated. As for the objectName[noparse]/noparse we could probably just return the startPtr (or the index) like Peter said and then you don't have to remember what it is in your code. As for method names it may be possible to do the hash when loading the function. But why not just use an enumeration starting at different values? Have certain areas reserved for common drivers (TV, VGA, Graphics, serial, etc) and then start everything else at some other value? I know its not ideal but I can't think of a better way unless we get a pre-processor for Prop-Tool (weren't there a couple of pre-processors written?)

    Good to have some feedback from some others smile.gif Time to start some more fixing.

    Steven
  • AribaAriba Posts: 2,690
    edited 2008-01-15 06:57
    stevenmess2004 said...
    (weren't there a couple of pre-processors written?)

    PreSpin:
    http://forums.parallax.com/showthread.php?p=655470
    SCCuM:
    http://forums.parallax.com/showthread.php?p=654555

    yeah.gif
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-15 09:31
    Thanks for the links Ariba, I may be able to use PreSpin to make using DOL easier. I'll have a better look at it next week sometime.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-15 10:39
    Another day and another version of DOL. See the top post. This one is now loading two objects from the SD card and demonstrating calls between the objects. You should see stuff on the screen on the VGA and TV output. There is still a fudge factor of -8 in the length of the VAR section. I think I just figured out what it is. Hippy is the -8 because we are reading the offset from the 8th memory position? Next update will focus on getting the documentation up to date and improved.

    Steven

    Post Edited (stevenmess2004) : 1/15/2008 10:47:27 AM GMT
  • hippyhippy Posts: 1,981
    edited 2008-01-15 16:33
    I'm afraid I haven't been closely following the development of your code, so I'm afraid I cannot relate that -8 to my simpler version and I'm not sure of its purpose.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-15 19:55
    Hippy, to get the amount of VAR space that I need to allocate, I read the initial stack pointer from the object header. When I subtract away the program length and the program start position I am left with 8 more bytes than I should have. It has happened on two different objects so it seems to be consistent. The -8 simple corrects for the extra bytes.

    Steven
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-16 10:15
    More documentation as promised. If you have a look at dummyObject2 and DYNDemo1 they should tell you almost everything you need to know. Also changed to not having the TV driver in the DOL object. This saves space and allows more memory for objects. See first post for new version.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-19 09:42
    There is another new version of DOL. This version is now useable. There is a bug with the aborts and I haven't tested the call to DOL for the SD card yet but everything else is working. See the first post.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-19 10:13
    I'm getting this error message when I try to upload the zip file. Any hints?
    * You cannot upload files that use MIME type : application/x-zip.
  • Harrison.Harrison. Posts: 484
    edited 2008-01-19 17:23
    I get the same error when I try to use firefox to upload files to this forum. I have to switch to IE to get around that error. You could always edit the browser MIME type on your computer, but that's just a pain and kind of a hack.
  • Ym2413aYm2413a Posts: 630
    edited 2008-01-20 01:21
    I can't wait to give this a try. [noparse]:)[/noparse]
    I remember me and a few other guys from around here talking about how something like this would help development of large programs.

    Thanks Steven!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Share the knowledge: propeller.wikispaces.com
    Lets make some music: www.andrewarsenault.com/hss

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-20 02:43
    Zip file is now working using Safari on a Mac smile.gif. If anyone uses this please let me know what you think. Any comments will be greatly appreciated (positive or negative). I was going to try to make it so that multiple objects of the same kind used the same code but I don't think I can do it (I just thought how I could but it will take some work to get it working and will be slower again. Who uses spin when they want speed anyway?)

    Steven
  • Ym2413aYm2413a Posts: 630
    edited 2008-01-24 06:48
    This works very well.
    I havn't had a single bug with it yet.

    Great work Steven.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Share the knowledge: propeller.wikispaces.com
    Lets make some music: www.andrewarsenault.com/hss

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-24 07:03
    Thanks. Hopefully I'll have a new version up tonight. Just a couple of small things and a keyboard/mouse driver. After that its time to try and get some event driven (from mouse and keyboard) code working.

    Steven
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-24 11:16
    Well, the update won't be tonight. There is a bug I have to find. :-(
  • Ym2413aYm2413a Posts: 630
    edited 2008-01-24 14:00
    *Aww* okay. [noparse]:([/noparse]
    I hope you find it.

    So far I havn't found a single bug, So that's good.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Share the knowledge: propeller.wikispaces.com
    Lets make some music: www.andrewarsenault.com/hss

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-01-26 04:31
    New version of DOL, see top post. Fixes a problem when unloading objects and should now be safe for use in multiple cogs although this is not tested yet. There is also a mouse driver in the demo.

    Steven
  • Ym2413aYm2413a Posts: 630
    edited 2008-01-26 14:24
    Thanks Steven. [noparse]:)[/noparse]
    I'll give this a try later after work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Share the knowledge: propeller.wikispaces.com
    Lets make some music: www.andrewarsenault.com/hss

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-09 05:00
    Can anyone see why this produces garbage on the screen. It is just an object that runs a modified version of Graphics_Demo. The changes I have made to Graphics_Demo are to make it single buffered and to store the bitmap in an array rather than at some arbitrary point in memory. Compile testKern and save it as kernal.bin onto your memory card. If you put a call to start the Graphics_Demo at the start of the methodRunner method in testKern and load it into the propeller (eeprom or ram) it works. Is Graphics_Demo or Graphics using some set address that I am not seeing?

    Some help would be great.

    Thanks

    Steven

    I am about half way through the next version of DOL which will allow for an inheritance and only loading VAR sections if the PUB and PRI sections are already loaded.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-06-22 12:22
    New version. See first post.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-07-11 13:26
    Another new version. I just busted my sd card interface and can't be bothered fixing it tonight so I wasn't able to test the last change that was supposed to make things uppercase. If its not making things uppercase, change the stdout.stdout(stdin.stdin+"A"-"a") to just stdout.stdout(stdin.stdin). This will just mirror what you type to the screen. It also spits out a bit of data onto the serial port so that I could see what was happening. The reason it took so long was because it wasn't working when I had the stdIn and stdOut streams the wrong way around. (seems really strange, wonder why smile.gif probably has something to do with doing this too late at night). There is also a object tree file that gives an idea of what I am working towards.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-07-11 22:46
    sdenson, I assume that since you deleted (you can't hide, it emails me all the postssmile.gif ) your post you figured it out. The place to change the pin assignments for the tv and keyboard is in the terminal file where they are started. Just change these two lines to whatever you are using
    disp.start(string("12"))
    
    and 
    
      key.start(string("26"))
    



    The build process goes like this.
    1. Compile the following files and save them with the following names. Then dump them onto your sd card
    - terminal - terminal.dol
    - tv_text_DOL - tv_text.dol
    - comboKeyboard_DOL - comboKey.dol
    - upperCase - upper.dol

    2. Compile SDM_DOL2_Core_V001 and load it onto your propeller.

    When it starts, DOL loads terminal. Terminal then loads tv_text as the standard output and standard error output streams and comboKey as the standard input stream. Then it waits for you to type something and loads that. If you type in "upper" it loads upper.dol and calls the start method with the standard input, output and error streams in the argument list. Upper then just echo's what you type to the screen using the standard input and output streams that it has been given.

    Plans for the future are to
    1. Finish DOL2 so that it unloads objects and a couple of other things
    2. Reorder/rename methods in the rest of the objects in the object tree file so that we can use more things as stdioe
    3. Write a pre-processor that fills in all these numbers and generates headers automatically.
    4. Write a post-processor/fix dol that gets rid of the header objects in the binary since they are just taking up space.
    5. Fix inheritance either by playing with the method table (hard but faster) or calling the parent object with code (easy but slower)
  • jazzedjazzed Posts: 11,803
    edited 2008-07-12 02:51
    Ya, I had a hard time waking up today[noparse]:)[/noparse]

    Been looking at a way to do a download/save to disk via serial port. This would be to make updates more convenient than they are now (thank Tom for not caching the SD card driver ... no choice on "safely removing" on windows though). I have working download "client/server" code from another project. Do you have a serial DOL?

    The basic methods you have for console services are interesting, but not having a basic driver suite is limiting. Being able to "extend" objects is interesting and a desirable alternative to the simple unixy file handle way, and I can see how it can be done. You know it will be difficult to design as well as use. Having the template headers is desirable for detecting buggy calls at compile time rather than crash time ... considing only one long per method, I don't see how getting rid of them is a win unless it is an option for deployment -vs- development.

    You should seriously consider the one line printf ideas: http://forums.parallax.com/forums/default.aspx?f=25&m=277986 Modules snprintf+itoatoi adds 301 longs for first use, but having many tv.dec, tv.out, etc... is fatter after a point and quite inconvenient. Eliminating blah.dec(n), blah.hex(n,d), etc from the stdout/stderr requirement is a win.

    You have a reasonable and expandable piece of work here. I think good communication of your design and usage could make it more embraceable by a larger piece of the community. Being able to easily replace components is a great advantage and will be very welcomed when the mythical PropII comes (which because of many items, makes a larger general computing platform possible).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-07-12 09:24
    That's weird, in the email your name is sdenson but online its jazzed. Maybe something for the tech support to look into?
    jazzed said...
    Ya, I had a hard time waking up today[noparse]:)[/noparse]

    Been looking at a way to do a download/save to disk via serial port. This would be to make updates more convenient than they are now (thank Tom for not caching the SD card driver ... no choice on "safely removing" on windows though). I have working download "client/server" code from another project. Do you have a serial DOL?
    Not yet, after I finish the unload code fixing more drivers is the next thing on the todo list.
    said...
    The basic methods you have for console services are interesting, but not having a basic driver suite is limiting. Being able to "extend" objects is interesting and a desirable alternative to the simple unixy file handle way, and I can see how it can be done. You know it will be difficult to design as well as use. Having the template headers is desirable for detecting buggy calls at compile time rather than crash time ... considing only one long per method, I don't see how getting rid of them is a win unless it is an option for deployment -vs- development.
    Getting rid of them gets rid of the need to maintain two copies of the same file for custom objects (its too easy to change one and forget the other). You would still need them for the standard objects.

    [noparse][[/noparse]qoute=""]You should seriously consider the one line printf ideas: http://forums.parallax.com/forums/default.aspx?f=25&m=277986 Modules snprintf+itoatoi adds 301 longs for first use, but having many tv.dec, tv.out, etc... is fatter after a point and quite inconvenient. Eliminating blah.dec(n), blah.hex(n,d), etc from the stdout/stderr requirement is a win.
    I could make it so that the snprintf object is passed in the parameter list like the stdin, stdout and stderr objects. Could add a str output to the standard output and get rid of the advanced input/output routines which would save space.
    said...
    You have a reasonable and expandable piece of work here. I think good communication of your design and usage could make it more embraceable by a larger piece of the community. Being able to easily replace components is a great advantage and will be very welcomed when the mythical PropII comes (which because of many items, makes a larger general computing platform possible).
    Yeah, once I get the terminal working better than I'll start writing some documentation and some better demo's. Maybe I could write the pre-processor for it smile.gif Only problem is that we can only have one file open at a time on one sd card. It should be possible though to load another complete driver for an sd card on different pins.
  • jazzedjazzed Posts: 11,803
    edited 2008-07-14 05:10
    Hi Steven,

    Tried a few things yesterday. The upperCase.spin file has a reference to Simple_Serial in it; I could not get that to work. I tried creating a serial_DOL as attached, but that doesn't work either. In american football terms: it's 4th and 10, all I can do is punt. Have a look please.

    Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-07-14 12:17
    I'll check into it tomorrow.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-07-15 10:28
    The problem is that I haven't finished the terminal yet so its not actually passing the arguments yet smile.gif. Also, I am using the first 3 longs for references to the standard input, output and error streams. In fact, I'll even say that I'll start the actual arguments at fifth long so that there is room for the format object if I want to use it. I'll have to fix up the terminal before its going to work properly. Does it work if you hardcode the numbers in? (I haven't fixed my sd card holder yet...)
Sign In or Register to comment.