gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > itcm, link scripts and the heap

#144353 - simonjhall - Wed Oct 31, 2007 11:08 pm

Yo,

I recently moved loads of code into itcm in order to improve performance a bit and also to reduce the main memory load a bit.
Well after doing this, I assumed that I'd be able to regain up to 32k of heap space, since the code would be resident in the itcm memory instead, but this wasn't the case. I forgot about this and now have decided to dig it up again since people seem to have problems loading a few levels due to a lack of RAM.

I seem to remember that in the early startup of a DS program, the memory protection unit gets set up, code gets copied into various places etc etc, and this is where code is sent to itcm allowing calls to these functions (from the main program) to work correctly. Well once they've been copied, the memory they originally occupied in main memory is no longer needed, right?

But poking through my elf and the link scripts says otherwise, and as a result I'm not able to win myself back that max 32k of main memory.
The link script basically says that *main* memory looks like this:

- the text section
- something else, which has the exact same size as the itcm section
- the bss section
- the heap.

Here's the sections header from my elf:
Code:
Program Header:
0x70000001 off    0x000779cc vaddr 0x0206f9cc paddr 0x0206f9cc align 2**2
         filesz 0x00000110 memsz 0x00000110 flags r--
    LOAD off    0x00008000 vaddr 0x02000000 paddr 0x02000000 align 2**15     <--- this is the text section
         filesz 0x000751d4 memsz 0x000751d4 flags rwx
    LOAD off    0x00080000 vaddr 0x01000000 paddr 0x020751d4 align 2**15     <--- this is the itcm section
         filesz 0x00004d74 memsz 0x00004d74 flags rwx
    LOAD off    0x00081f48 vaddr 0x02079f48 paddr 0x02079f48 align 2**15     <--- this is the bss section
         filesz 0x00000000 memsz 0x00068d5c flags rw-
private flags = 4000002: [Version4 EABI] [has entry point]
Even though I've got 16k currently in the itcm section, there's still a 16k 'gap' between the data section and the text section - and I want it back!
How trivial is it to wiggle the linker script in order to get the DS startup code (in crt0.s?) to work whilst winning me back some memory after code has been copied into itcm?

Ta as ever :-)
_________________
Big thanks to everyone who donated for Quake2

#144469 - simonjhall - Fri Nov 02, 2007 11:28 am

Nobody?
_________________
Big thanks to everyone who donated for Quake2

#144473 - freemaan - Fri Nov 02, 2007 1:04 pm

I think you can move "_end = . ; __end__ = . ; PROVIDE (end = _end);" above the BSS section in the linkerscript.
_________________
My other nickname: davido2

#144479 - ingramb - Fri Nov 02, 2007 6:45 pm

Something like this maybe...

Rearange your sections like so:

- the text section
- the bss section
- something else, which has the exact same size as the itcm section
- the heap.

Define __end__ to come after the bss section. I think this might work, though you may want to take a peek at the arm9 crt0.s and make sure it's not going to use the end lable before it copies the itcm stuff out of main ram.

I may play around with this myself when I get home...I need more memory too =)

#144524 - wintermute - Sat Nov 03, 2007 7:23 am

If 32K is going to make a difference you have other problems really.

I did try fiddling this stuff around a while back but I had trouble convincing the linker to accept the bss section being overlaid on other sections.

I'll have another look and see what I can do though.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog