Shop OBEX P1 Docs P2 Docs Learn Events
Re-using Hub space after a cog is loaded - example — Parallax Forums

Re-using Hub space after a cog is loaded - example

Cluso99Cluso99 Posts: 18,069
edited 2010-05-08 12:51 in Propeller 1
My 1pinTV driver reuses the hub space as the screen buffer after the cog is loaded. If the screen buffer is larger than the cog space, more space is added to the cog DAT section (at the end) which may also increase past the normal cog maximum of 496 longs (496*4 = 1988 bytes).

See the OBEX Debug_1pinTV or the thread http://forums.parallax.com/showthread.php?p=885731

If the 1pinTV and 1pinKBD were defined in the one module I could use the hub space for the keyboard for any extra screen buffer characters.

This is a good example of re-using hub space. Any video driver could use this method, thereby re-using a large block of hub space.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:

· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
«1

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-05-06 11:50
    This is a great technique. Sooner or later one seems to run out of memory. Using this technique with 7 cogs can reclaim nearly half the hub ram. With some code to track where the cog code ended up in hub, it ought to be possible to piece to gether all the bits of 1988 bytes and create one big array space.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • SapiehaSapieha Posts: 2,964
    edited 2010-05-06 13:07
    Hi Cluso, Dr_Acula.

    Cluso. NICE.

    Dr_Acula.
    I'm Postulated some time ago (More at once) - Redesigning Propeller tool's binary structure to have possibility to reusing HUB memory as one chunk.
    But it was no many people that say it is BIG win.

    Regards

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • BradCBradC Posts: 2,601
    edited 2010-05-06 13:28
    Sapieha said...
    Hi Cluso, Dr_Acula.

    Cluso. NICE.

    Dr_Acula.
    I'm Postulated some time ago (More at once) - Redesigning Propeller tool's binary structure to have possibility to reusing HUB memory as one chunk.
    But it was no many people that say it is BIG win.

    I've been thinking about this lately. Let me float my concept and see what you think.

    The key to a reusable DAT section is it being exclusively code to load into a cog. My idea is to define an extra block (something like DATX). The idea is the DATX block must start with the cog code (org 0) and the first symbol in that block is how it is referenced.

    All DATX blockx would be packed and located at the end of HUB ram in the binary with only access to the first symbol in each DATX block accessible from SPIN to use in a cognew.

    Just a thought. I've given it passing thought as to how it might be implemented in the compiler, but not much more than that.

    All variables in the DATX blocks would be loaded via reference in par or compile time definitions. No accessing the ram from spin prior to cog load.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
  • pullmollpullmoll Posts: 817
    edited 2010-05-06 13:40
    BradC said...
    No accessing the ram from spin prior to cog load.

    Why not? I see no reason in forbidding to preset cog variables in their hub RAM location. It's often more convenient to preset calculated values in Spin rather than PASM, because you have e.g. multiplication and division at no extra cost. Isn't packing DATX fragments nothing else but a shift of their base address?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pullmoll's Propeller Projects
  • pullmollpullmoll Posts: 817
    edited 2010-05-06 13:42
    Cluso99 said...
    This is a good example of re-using hub space. Any video driver could use this method, thereby re-using a large block of hub space.

    I'm doing the same with the combined SD SPI and XMM driver that hairymnstr wrote. Its cog RAM is re-used as I/O buffer for the SD card access.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pullmoll's Propeller Projects
  • BradCBradC Posts: 2,601
    edited 2010-05-06 13:47
    pullmoll said...
    BradC said...
    No accessing the ram from spin prior to cog load.

    Why not? I see no reason in forbidding to preset cog variables in their hub RAM location. It's often more convenient to preset calculated values in Spin rather than PASM, because you have e.g. multiplication and division at no extra cost. Isn't packing DATX fragments nothing else but a shift of their base address?

    It is. The issue is variable access in the spin in interpreter is based on the relative address inside the object. In the case of a DATX block the object base is disconnected from the address of the DATX block. In addition, you don't know where the DATX block is going to be located ahead of time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
  • SapiehaSapieha Posts: 2,964
    edited 2010-05-06 14:12
    Hi BradC.

    Nice starting idea.
    BUT fro usable design we need talk more on it - Maybe TALK with Parallax to organize it THAT them can even incorporate same changes in Propeller Tool.

    Thanks and Regards
    Christoffer J

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • BradCBradC Posts: 2,601
    edited 2010-05-06 14:33
    Sapieha said...
    Hi BradC.

    Nice starting idea.
    BUT fro usable design we need talk more on it - Maybe TALK with Parallax to organize it THAT them can even incorporate same changes in Propeller Tool.

    Well I thought I'd kick the ball off anyway. I don't have a mortgage on wisdom.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-05-06 14:37
    I use cmalloc.spin to allocate blocks of memory from the available space.· A "free" basically adds a chunk of memory with a linked list header back to the free list.· There is no reason that a "free_mem(ptr, size)" method couldn't insert a linked list header·into a chunk of memory that is no longer needed and add it to the malloc free list.· Hmm, I think I'll add that to cmalloc.spin.

    Dave
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-06 16:42
    BradC said...
    The issue is variable access in the spin in interpreter is based on the relative address inside the object. In the case of a DATX block the object base is disconnected from the address of the DATX block. In addition, you don't know where the DATX block is going to be located ahead of time.
    No. You can access the cog data to be loaded (the DAT section) at a hub address from spin before loading instead of using PAR to pass parameters. Look at the start routine in my Debug_1pinTV.spin (not the xxx_demo.spin) where I calculate the FRQA value required according to the current CLKFREQ and set·xfrqa in the cog's hub code ready for the cog to use after the cog is loaded.

    Essentially, we are just using the physical hub address using spin. If the cog requires to access this as hub buffers, then you still pass the address of hub using PAR.

    What is needed without having to put all the objects DAT codes together manually so it can all be used as buffers (,etc... i.e. a font loaded later from SD or flash), is a way to somehow (compiler directive) put the·DAT codes sequentially by the compiler and not intermingled with spin code. Perhaps a DATX is needed to just put these together because there are cases where·some DAT code cannot be re-used.

    Any easy ideas Brad?

    BTW I am also using the compiler to create a lot of the TV parameter calculations using the compiler. Look at the way I just get the user to·edit the values of·PAL, ocols and orows at edit time. Then the compiler calculates all the related timing constants, including long constants and immediate constants. The only calculation that must be done online is the FRQA value which depends on CLKFREQ.

    We are almost at the stage of loading cogs from flash/SD via a smaller hub buffer. I have plans to do this in SphinxOS by loading a minute cog stub loader into cog $1F0 shaddow space to take zero footprint in cog. My spin/pasm debugger runs in shaddow ram and takes zero cog footprint.

    @pullmoll: Yes, a number of people are re-using hub space. My 1-pinTV is a fairly simple program to follow for how to do this and this object is quite·well documented now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-06 17:02
    Just to expand the discussion, there is a problem on the Catalyst thread http://forums.parallax.com/showthread.php?p=900063·where one of the Z80 emulators·required cog0.

    It would better to not demand any specific cogs for anything.
    ...And yes guys, I know there are some I/O pins better suited to specific cogs. But various loaders are now being built and you do not know how they have preset any cogs and how your code is being called.
    It is my aim to modify ZiCog (and others?) to use SphinxOS to preload the I/O drivers so that ZiCog, etc do not need to know whether it is talking to a PC & Terminal program, another prop running a terminal(s) program, or a terminal program on the current prop (e.g. my 1pin TV & Kbd drivers or TV or VGA and PS2 Keyboard drivers). This is extremely close, just not had enough time - I need to move the SphinxOS rendezvous locations from $7FFF as this will be required to point to the lowest hub code used from the top down, so other programs will know where the resident stuff is located.

    I would also like the SD driver to stay-resident so we all don't use different SD/fsrw·drivers as we do currently. mpark placed all the code into 3 cogs for Sphinx, but we do not have the luxury of 3 cogs with a lot of programs. This way, we could have the raw SD access and some FAT16/31 basic stuff in 1 cog. Any extras (file access, etc) could be done by another object and used by the end user under the OS.

    Does this make sense?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-05-07 02:50
    I reused hub space in the original dracblade and I think it has been independently used by others. Cluso has documented the technique. It gets a bit more complicated when you reuse multiple cogs as you need to track the location of each one, and then need some code that concatenates it all together. It would be great if this were simpler to do.

    Regarding this being added to the proptool, well there are quite a number of us writing code that simply cannot compile on the Proptool any more due to conditional compilation. On BST we have #define in its various flavours. How about #packcogs and then have keywords after that, eg beginning, end, @nnnn to tell it where to put the code.

    Having written compilers, the problem usually is that you don't know where things are going to end up later, and that can be usually be solved by adding more passes through the code. I suppose the question for Brad is whether he has enough control over the compiler to do this, and if so, is the problem solvable?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller

    Post Edited (Dr_Acula) : 5/7/2010 3:01:01 AM GMT
  • mparkmpark Posts: 1,305
    edited 2010-05-07 04:31
    Cluso99 said...
    BradC said...

    The issue is variable access in the spin in interpreter is based on the relative address inside the object. In the case of a DATX block the object base is disconnected from the address of the DATX block. In addition, you don't know where the DATX block is going to be located ahead of time.
    No. You can access the cog data to be loaded (the DAT section) at a hub address from spin before loading instead of using PAR to pass parameters. Look at the start routine in my Debug_1pinTV.spin (not the xxx_demo.spin) where I calculate the FRQA value required according to the current CLKFREQ and set xfrqa in the cog's hub code ready for the cog to use after the cog is loaded.
    What do you mean, "No"? Of course you can set xfrqa in the DAT section, but how does that address the problem Brad mentioned with DATX?
  • BradCBradC Posts: 2,601
    edited 2010-05-07 04:38
    Cluso99 said...
    BradC said...

    The issue is variable access in the spin in interpreter is based on the relative address inside the object. In the case of a DATX block the object base is disconnected from the address of the DATX block. In addition, you don't know where the DATX block is going to be located ahead of time.
    No. You can access the cog data to be loaded (the DAT section) at a hub address from spin before loading instead of using PAR to pass parameters.

    You appear to have missed "In the case of a DATX block the object base is disconnected from the address of the DATX block. In addition, you don't know where the DATX block is going to be located ahead of time.". I'm saying it may well be very difficult or quite unclean to map the symbols from the relocated DAT block into the compilers symbol table for that object as at object compile time the compiler has no idea where that chunk of data is going to be relocated to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Are you suggesting coconuts migrate?"
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-07 07:33
    Brad had said that "The issue is variable access in the spin interpreter is based on the relative address inside the object." I interpreted this to mean that within a spin object, you cannot access the DAT section of the cog code. I merely pointed out this was incorrect as you can definately do it - I do it often to set parameters within the cog before loading the cog.

    The point I raised with calculating FRQA at runtime using CLKFREQ was a seperate issue. I am doing this because I can release a binary which could be loaded by SphinxOS and the binary does not know of the clkfreq at compile time.

    However, the point is that it would be nice to tell the compiler to place certain DAT objects sequentially so we can reuse this space for multiple buffers, etc and their sizes may not match the dat cog code sizes. Another problem is a huborg statement so that we can force certain code to be compiled at a specific hub address.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • BradCBradC Posts: 2,601
    edited 2010-05-07 09:29
    Cluso99 said...
    However, the point is that it would be nice to tell the compiler to place certain DAT objects sequentially so we can reuse this space for multiple buffers, etc and their sizes may not match the dat cog code sizes.

    Which is precisely why I detailed a method for doing it and went into the limitations surrounding that concept.

    A spin object has 3 parts.
    - The Method Table
    - The DAT Section
    - The Spin Methods

    All addressing inside that neat little package of bits is relative. When you compile the DAT section separately and place it somewhere else in the hub (sandwiched between 4 or 5 other dat sections packed at the end of memory for example) you have a disconnect between the relative addresses in the SPIN object and the DAT section itself.
    Cluso99 said...
    Another problem is a huborg statement so that we can force certain code to be compiled at a specific hub address.

    Why would you want to do that?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Are you suggesting coconuts migrate?"
  • SapiehaSapieha Posts: 2,964
    edited 2010-05-07 10:06
    Hi BradC.

    It is reprint of my post from another thread.

    Hi Jessica Uelmen (Parallax).

    I'm are not "C" lover - BUT if that "PMC" can give us New "Propeller Tools" That can compile both SPIN and Semi "C"-PMC that are very appreciated.

    BUT
    1. That New "Propeller Tools" need have possibility to Compile DAT-PASM snippets as separate xxx.bin files without HEADER/FOOTER only RAW COG-PASM Program DAT file's.
    ... To be possible to call from both "C" and "SPIN" as In-line ASSEMBLY to be executed from any COG and only communicate with them by Given HUB-Memory BOX's.

    2. To that "Propeller Tools" need have some new directive's In DAT section -COGDATStart, HUBBOXADD=XXXXX, (This area need have possibility to be visible to compiler that it can use that addresses in "C" and "SPIN" but add Code to compiled Program at END of code REUSED after start of program) COGDATEND,

    Regards
    Christoffer J

    Ps. It is that functions in Compiler I want to have.
    "HUB-Memory BOX's" - means Mail-Boex betwen Spin programs and COG programs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-05-07 11:07
    Re "When you compile the DAT section separately and place it somewhere else in the hub (sandwiched between 4 or 5 other dat sections packed at the end of memory for example) you have a disconnect between the relative addresses in the SPIN object and the DAT section itself."

    I can see that would be a problem for Cluso's program that loads bits of cog code off a sd card that might have been compiled earlier. But what about the case where the entire package is being recompiled? Is it possible to recalculate all those relative addresses as the complete binary is being created?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-05-07 16:00
    Maybe nobody understood my previous comment, so I'll try again.· If your Spin program uses a heap memory manager you can just add the cog DAT space to the heap after the cog has been loaded.· For cmalloc, I plan on adding a free_raw method which only requires 8 longs of spincode.· It will look like this:

    PUB free_raw(ptr, size)
    '' Add the "raw" memory block at "ptr" to the free list.  The memory block
    '' must be long-aligned, and size must be a multiple of four.
      if size < 4
        return
      repeat until not lockset(locknum)
      word[noparse][[/noparse]ptr][noparse][[/noparse]BLK_SIZE] := size
      meminsert(ptr) ' Add to the free list
      lockclr(locknum)
    
    


    A sample of code that could use this would look something like this:

    OBJ
      mem : "cmalloc"
      
    DAT
      buffer long 0[noparse][[/noparse]16]
    PUB start
      cognew(@entry, @buffer)
      waitcnt(8192 + cnt) ' Wait for cog to load
      mem.free_raw(@entry, @pasm_end - @entry)
    DAT
                            org
    entry                   mov     t1, par
                            rdlong  param, t1
    loop
                            ' *** more PASM cog code ***
                            jmp     #loop
    pasm_end
    ' Uninitialized data
    t1                      res     1
    param                   res     1
    
    

    After the cog is loaded the·memory·will become·available·for reuse·by calling malloc.· It seems pretty straight-forward.
    Dave
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-07 16:18
    A heap won't solve Cluso99's problem, though, since his buffer memory has to be contiguous. And that entails moving the DATs to the high end of the hub before they're loaded.

    The trick may be to put the assembly code in a separate object with a start stub to cognew it, then make sure the entire object gets loaded into high hub memory (via a loadhigh pragma, perhaps). An additional accessor function could provide the ability to poke initial values into the DAT before it gets loaded into the cog, if you want to do it that way. In any event, the start and accessor function(s) would be one-time executes, anyway, and could be safely overwritten. At least, this seems to be the most "Spinnish" way to accomplish the stated goal.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 5/7/2010 4:23:35 PM GMT
  • BradCBradC Posts: 2,601
    edited 2010-05-07 17:05
    Sapieha said...

    1. That New "Propeller Tools" need have possibility to Compile DAT-PASM snippets as separate xxx.bin files without HEADER/FOOTER only RAW COG-PASM Program DAT file's.
    ... To be possible to call from both "C" and "SPIN" as In-line ASSEMBLY to be executed from any COG and only communicate with them by Given HUB-Memory BOX's.

    bstc can do that now. See the (-c) command line option. You need a public object in your source file (it has to be a valid spin object) but it will spit out only the dat section with no header or footer into a .dat file.

    I'm not getting the mailbox between spin and dat, but I need to re-read the threads a bit more to try and grok what you are after.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Are you suggesting coconuts migrate?"
  • BradCBradC Posts: 2,601
    edited 2010-05-07 17:06
    Phil Pilgrim (PhiPi) said...
    A heap won't solve Cluso99's problem, though, since his buffer memory has to be contiguous. And that entails moving the DATs to the high end of the hub before they're loaded.

    Not only that, but the memory manager consumes more memory itself. Much nicer to have the compiler do it for you and not worry about additional code to juggle bits around.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Are you suggesting coconuts migrate?"
  • SapiehaSapieha Posts: 2,964
    edited 2010-05-07 17:33
    Hi BradC.

    2. To that "Propeller Tools" need have some new directive's In DAT section -COGDATStart, HUBBOXADD=XXXXX, (This area need have possibility to be visible to compiler that it can use that addresses in "C" and "SPIN" but add Code to compiled Program at END of code REUSED after start of program) COGDATEND,

    In Program
    COGDATStart
    HUBBOXADD=XXXXX,xx
    > Directive to Compiler for have Start addresses Of Mail-Box(XXXXX) and bytes else LONGS(xx) reserved.

    .......

    Some PASM CODE




    .......
    COGDATEND


    It was something that I have thinking on. And that Blocks Compiled separate and added at last to .BIN with loading HEADERS and all discarded after successfully loaded COG's.
    and reused by Compiled Program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-05-07 20:33
    BradC said...

    Not only that, but the memory manager consumes more memory itself. Much nicer to have the compiler do it for you and not worry about additional code to juggle bits around.
    Yes, cmalloc.spin does take up 108 longs with the free_raw method added.· And there can be fragmentation problems.· And there are 4-bytes of overhead for each memory chunk that is allocated.· However, there are applications where a memory manager comes in real handy.
    Dave
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-07 20:34
    There are a number of problems being addressed here and so a bit of confusion reigns.

    My requirement's are
    1. Ability to direct the compiler to join certain DAT sections of code contiguously so they can be re-used. The reason they must be contiguous is that a screen buffer is typically longer than a single DAT (cog) code. Currently I am wasting additional hub space beyond the cog. I think we need some capability to order these but I am not sure how is easiest. This is because you also need to coordinate the release of the hub dat section for the buffer. Take my screen example. Once the cog is loaded and begins, the first thing it does is clear the screen buffer. Now if it overlaps the keyboard hub cog space and the keyboard has not been loaded yet, hey we just corrupted the keyboard code before it gets loaded.
    2. Sphinx is defining upper hub memory from $7FFF downwards. I want it to be able to define some buffers downwards from the top. The first long is a pointer to the last lowest used. The next few are "rendezvous" longs where characters are passed back and forth between cog drivers and the application software (spin/pasm/c/basic). Next should come the SD bufer (512/4 longs)followed by the screen buffer(s) if they exist. It would be nice if we could place the interface code to the drivers up here, but it is OK to compile them into the Sphinx sub-programs which get loaded by SphinxOS as binaries from hub $0000 as normal - it is just that they are aware of the rendezvous locations and the buffers (they may have to ask the driver for its location via the relevant rendezvous. A Sphinx sub-program (also called Sphinx aware) would be like DIR, ZiCog (a new version that no longer knows what it is driving - serial or keyboard and screen - because it is now going via a driver. This means these programs may now be available as a binary, already compiled. And that is why my screen driver is able to calculate FRQA using the live CLKFREQ when it loads.
    3. So the third point (which is also where I think Sapieha is heading) is to be able to have seperate object binaries which can be loaded into a different base address at run time. I don't know if this is possible, but certainly from what I have seen, spin should be capable of this as an object seems to be relocatable. The other requirement that Sapieha talks about is being able to force the compiler to leave gaps in the compilation, and so make certain parts start at specific hub addresses.

    There are multiple things we are after, for differing reasons. I don't know the best solutions and I guess each one will have to be dealt with as a seperate piece of the puzzle. It does help to have an understanding of everyone's objectives.

    For Dave: Yes I did see your allocation plan. However, at this time I don't see this as being required, at least from my perspective. It just seems to be placing too much overhead on a little processor. The prop (certainly Prop I) is not an intel processor and·I certainly do not want the baggage that windoze has. I just want a small operating system like back in the early days of CPM and DOS. I am not actually talking about emulators here (like ZiCog, etc) - they are a means to an end. We should be able to develop via members on the forum a great little operating system to play with. This is not meant for professional use. Michael Park has done a great job with Sphinx because it can do the basic functions of DIR, REN, COPY, etc. It can also compile code on the Prop. It just needs to be taken to the next stage of SphinxOS, and jointly, rather than fragmenting various OS flavours.

    Brad has provided us with a great cross-platform compiler and the extras such as #define. He has an embedded simple terminal and a loader. It makes the whole development process so much simpler than PropTool & PST. And a number of us cannot live without these #defines.

    So, to recap. A number of us have been re-using cog space for some time. However, I have just come up against a reason that it needed to be longer than the actual hub space ocupied by a single cog. With the help of the forum, I devised a way to allocate additional hub space with a compiler command. This space is just zero filled (initially just wasted) until required by the buffer because I cannot place DAT cog objects together contiguously unless I combine them into a single object (like combining the cog keyboard DAT and cog TV DAT into a single object).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-05-07 21:34
    OK, I re-read the thread, and I see where I was missing the main point.· However, I do want to point out that heap management is not as complex as some people think.· It's implemented in 100 longs of spincode.· I do see that it doesn't solve the problem where a program needs a large chunk of contiguous memory, and the re-usable· cog images are scattered thourgh the RAM.

    The DATX idea sounds good, but why limit it to just DAT sections.· Why not reuse the entire object that is used to load a cog.· Once the cog is loaded you don't need the code that initialized the PAR table or issued the cognew, and you don't need its method table.· Of course, you may need another object that talks to the cog after it's loaded, and provides an interface to it.

    So what I think·is needed is a section of memory located some number of bytes after the stack that contains all the throw-away objects.· This could include objects that have nothing to do with loading cogs, but run some initialization code.· So the Prop tool just needs to know the desired cog 0 stack size, and which objects to load after the stack.

    Dave
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-08 04:06
    Dave: Yes. If you look at SphinxOS and the ixxx objects, they are the spin interfaces required for a general driver without the need to know the specifics. i.e. They have the chr/out/tx, dec, str, hex, bin functions for the generalised output functions and in.rx, rxavail, peek, etc for the generalised input functions. They do not load or initialise the object, so their footprint is smaller.

    Perhaps the eaiser way rather than reusing the hub space is to have the OS load the driver cogs as seperate binaries and allocate simply the buffers required from the top down. Then the OS loader will not permit a binary to run that encroaches on any of the hub ram allocated (top down). Sphinx sort of does this now but only in a fixed way at present as $7FFF long has not been freed for relocation yet in order to have the top of hub stored here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-05-08 07:11
    Re Cluso Take my screen example. Once the cog is loaded and begins, the first thing it does is clear the screen buffer. Now if it overlaps the keyboard hub cog space and the keyboard has not been loaded yet, hey we just corrupted the keyboard code before it gets loaded.

    Presumably you would load up things like keyboard and display at startup, so you could change the order and do keyboard first?

    Reloading cogs is another matter. This caught me out on an earlier version of the dracblade when I was recycling the uart object code space, and then needed to restart that object for a baud rate change. It certainly simplifies things if cogs are only ever loaded once. But I take it sphinx objects can be loaded and reloaded?

    Thinking through the problem of joining together dat sections to make lots of space, and working with the current compilers, the usual code is
    object1
    spin
    dat

    object2
    spin
    dat

    etc

    variable names are local within objects, so combining them into one big spin file is not as simple as it sounds. But, hypothetically, if all objects all had unique variable names, you could rewrite your code in one single text file
    object1 spin
    object2 spin
    object 1 dat
    object 2 dat

    and the dat sections ought to come out one after the other?

    The problem I see is that objects were never written to be used as part of one big text file. I spent a day trying to get just three objects to work together with no conflicting variable names. If you are going to go to all that effort, may as well spend a tiny bit more time and rewrite objects as Sphinx objects, with the stardard I/O locations at known locations in hub.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-08 07:28
    The naming conflict you refer to could be alleviated if the compiler permitted user-definable namespaces. As it is, it makes a feeble bow in that direction with the :local PASM labels, which can be reused. But Spin programs cannot "see" these labels for such purposes as poking initialization data into them. And once you define a global long at the end of your PASM code, all the reses after it have to be global, too. Even an SXASM-like global:local notation would be helpful in this regard. But defined namespaces would be the ultimate luxury.

    -Phil
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-05-08 08:08
    defined namespaces? That sounds intriguing. So say you took 5 objects and copied and pasted them into one big text file, and then at the beginning and end of each object you had a label to say it was a 'new object', the compiler could treat that as if it had loaded a separate object?

    But you could also have global variables, and in particular, you could have the variables that you use to link spin code to dat code, even when those bits of code are not contiguous. Then you can put all the dat at the end as a group.

    It is a different way of looking at the same problem. From the point of view of the person who writes the compiler, if each block of code has a defined namespace, then a bit of code that starts with #NameSpace1 and has a variable Variable1 can be tracked by the compiler as variable NameSpace1:Variable1 So the compiler can link up bits of spin and dat code that might be at either end of a program. Is this possible?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller

    Post Edited (Dr_Acula) : 5/8/2010 8:26:31 AM GMT
Sign In or Register to comment.