Shop OBEX P1 Docs P2 Docs Learn Events
Aligning table data in DAT sections — Parallax Forums

Aligning table data in DAT sections

What's the best way in spin to align a table in a DAT section to a 512 byte boundary?

In the SPIN2 documentation I can only see ALIGNW and ALIGNB capabilities but not a general purpose align directive.

Is there some trick that could work to roundup the current $ pointer to the nearest 512 bytes to pad the DAT section without using absolute address hacks? Something like this maybe?

DAT
padding byte 0[$+512 & !511]
aligned_table file "table.dat"

Comments

  • roglohrogloh Posts: 5,786
    edited 2022-08-11 05:45

    Umm, maybe that should be:

    padding byte 0[512-($ & 511)]
    

    Update: this approach seems to work in Flexspin anyway. Hopefully PropTool works the same.

  • evanhevanh Posts: 15,915

    Yeah, that ain't gonna work in Pnut/Proptool unless it's pure Pasm code. The $ won't have a compile time hubRAM address in official Spin2. Only a cogRAM address within an ORG/END.

  • Is there a way then in PropTool?

  • evanhevanh Posts: 15,915
    edited 2022-08-11 06:23

    I haven't tried. But Pnut works on the principle of the program it compiles can be subsequently placed anywhere in hubRAM without the compiler's knowledge of where. Presumably longword aligned though. It'll work from a base address with relative offsets.

  • evanhevanh Posts: 15,915
    edited 2022-08-11 06:34

    What you probably want is memory allocation management API. Not something that exists at the moment.

    The stack and heap could both make use of such an API. The mailbox system could be part of it. And would be a clear foundation for an OS. Which could be used for self-hosted dev.

  • Seems a bit limited if there isn't a way to do this. I guess there is a way if you add 512 bytes before the table data starts and do a longmove of the table contents to the next lowest 512 byte boundary before the table start address. A bit ugly but probably doable.

  • evanhevanh Posts: 15,915

    @rogloh said:
    Seems a bit limited if there isn't a way to do this. I guess there is a way if you add 512 bytes before the table data starts and do a longmove of the table contents to the next lowest 512 byte boundary before the table start address. A bit ugly but probably doable.

    Yes, a large array with runtime address maths would work.

Sign In or Register to comment.