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.

Coding > running code in DS' shared iwram

#132770 - Ant6n - Fri Jun 29, 2007 6:30 am

I am trying to run code in shared iwram on the arm9 side. I started with the devkitpro arm7/arm9 template. My main is this:

Code:
#include <nds/arm9/console.h> //basic print funcionality

#include "asm.h"
#include "dssystem.h"

#define SHARED ((vuint32*)0x03000000)
typedef u32 testfunction(u32 in) __attribute__ ((long_call));

int main(void) {
   videoSetMode(0);
   videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
   vramSetBankC(VRAM_C_SUB_BG);
   SUB_BG0_CR = BG_MAP_BASE(31);
   BG_PALETTE_SUB[255] = RGB15(31,31,31);
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
   
   //set iwram to belong to DS
   REG_WRAMCNT = 0;
   
   //copy the asm stuff
        testfunction *ptest2 = (testfunction *)SHARED;
   memcpy(test,SHARED,testlength/4);
   
   iprintf("\n\nshared wram register of arm9: %d\n",REG_WRAMCNT);
   iprintf("location of 'test' function: %x\n",test);
   iprintf("testlength %d\n",testlength);
   iprintf("first byte of test/sharedram: %x / %x\n",((u32*)test)[0],SHARED[0]);
   int n;
   //n = ((*ptest2)(0x4000100));
   iprintf("Test returned: %d\n",n);
...etc

and the function to run is this:
Code:

   .SECTION    .ewram,"ax",%progbits
   .ALIGN
   .POOL

   .ALIGN
   .GLOBAL     test
   .GLOBAL      test_end

@test: u32 -> u32; r0 holds 4000100h, returns time of execution in 33MHz cycles
test:
   @first set up timer
   mov r1,r0
   mov r2,#0         @timer0count = 0
   strh r2,[r1]
   mov r2,#(1<<7)      @timer0control = tmr-mode1 | timer-start
   strh r2,[r1, +#2]
   

   .rept 20
   add r2,r4,r5
   add r3,r6,r6
   .endr
   ldrh r0,[r1]      @read timer value
   
   bx lr
test_end: nop


I use this awkward way of doing things because the standard linkscript doesnt define a shared wram section, and i dont know how modify it appropriately.
This works in nogba, albeit only if the function is small. If i use .rept 100, then the rom crashes. On real hardware this thing doesnt work at all (crashes before printing anything). I tried memcpy, dmacpy and swicopy, but none seem to work. If I remove the comments and actually run the testfunction in shared ram, the rom crashes, even if the copying worked.

#132847 - Ant6n - Sat Jun 30, 2007 4:14 am

ok, i guess the above help request wasnt very well done. So I ask simple:
how can one run code in shared wram?
thx, anton

#132858 - wintermute - Sat Jun 30, 2007 4:14 pm

The latest linkscripts and default arm7 core reserve the switchable iwram for ARM7 exclusive use. Nintendo official code also does this, probably for similar reasons.

If you're looking for fast memory on the ARM9 then use the 32K itcm. You can do this by either naming the file .itcm.c/.itcm.cpp or using the ITCM_CODE macro in the libnds headers.

void myITCMfunc() ITCM_CODE;

void myITCMfunc() {

blah

}

you should separate itcm code into separate files *regardless* of which way you do it. The file naming option automatically switches to arm mode.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#132859 - Ant6n - Sat Jun 30, 2007 4:46 pm

I use itcm, but they way things are looking right now, my core might end up being being around 48 K - and this is already completely crunshed. I was thinking that i could put some stuff in the shared ram, because it appears to have 0 waitstates at a 33MHz bus speed, which would mean having half itcm speed compared to ewram, which gives almost 6 times itcm speed (assuming constant cache misses).