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 > SWI doing interesting things

#52968 - chishm - Mon Sep 05, 2005 3:43 am

I was messing around trying to get the ARM9 back into a PassMe startup loop using this code:
Code:
// Return to loop
*((vu32*)0x027FFE04) = (u32)0xE59FF018;    // ldr pc, 0x027FFE24
*((vu32*)0x027FFE24) = (u32)0x027FFE04;    // Set ARM9 Loop address
asm volatile("bx %0" : : "r" (0x027FF000) );

However, that didn't work. The ARM9 would return to the loop (I think) but I couldn't break it back out by changing the jump address. Out of frustration I though I would just reset the whole thing, calling:
Code:
asm volatile(".thumb\n  swi 0x00\n");  // Soft reset

I thought this would reset the NDS. The weird thing is, it only reset the ARM9, which entered a FlashMe loop. This is just what I wanted.
For interest, this is the exact code:
Code:
// Return to loop
*((vu32*)0x027FFE04) = (u32)0xE59FF018;    // ldr pc, 0x027FFE24
*((vu32*)0x027FFE24) = (u32)0x027FFE04;    // Set ARM9 Loop address
asm volatile(".thumb\n  swi 0x00\n");  // Soft reset

#53020 - tepples - Mon Sep 05, 2005 3:14 pm

chishm wrote:
I was messing around trying to get the ARM9 back into a PassMe startup loop using this code:
Code:
// Return to loop
*((vu32*)0x027FFE04) = (u32)0xE59FF018;    // ldr pc, 0x027FFE24
*((vu32*)0x027FFE24) = (u32)0x027FFE04;    // Set ARM9 Loop address
asm volatile("bx %0" : : "r" (0x027FF000) );

However, that didn't work. The ARM9 would return to the loop (I think) but I couldn't break it back out by changing the jump address.

Could it be a cache coherency problem? Did you try setting that memory to be uncacheable?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#53090 - chishm - Tue Sep 06, 2005 1:06 am

That's what I thought, but using Darkain's code to clear and disable the cache didn't fix it. I know it did something, because all my other functions (held in cache) disappeared. However, the problem is solved now, in what I think is a much more elegant way.

#145786 - knight0fdragon - Thu Nov 22, 2007 1:25 pm

ok, could someone please tell me what I am missing, because this is really starting to bug me.

I am trying to get the arm9 into a passme style loop while the arm7 does its own thing, but the problem I am having is that everything? is resetting, and I just want the arm9 to reset into the passme loop.

Here is my code
Code:

int main(void)
{
//---------------------------------------------------------------------------------
  irqInit();
  irqEnable(IRQ_VBLANK);
 
  touchPosition touchXY;
  videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);   //not using the main screen
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);   //sub bg 0 will be used to print text
  vramSetBankA(VRAM_A_MAIN_BG);
  vramSetBankC(VRAM_C_SUB_BG);
  BG0_CR = BG_MAP_BASE(31);
  SUB_BG3_CR = BG_BMP16_256x256;
  SUB_BG3_XDX = 1 << 8;
  SUB_BG3_YDY = 1 << 8;
  BG_PALETTE[255] = RGB15(31,31,31);   //by default font will be rendered with color 255
 
  //consoleInit() is a lot more flexible but this gets you up and running quick
  consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16);
 
  iprintf("\n\n\tHello World!\n");
  bool vramC = true;
  while(1)
  {
    scanKeys();
    int keyPressed = keysDown();
    if (keyPressed & KEY_A)
    {
      vramSetBankC(VRAM_C_ARM7);
      swiWaitForVBlank();
      vramSetBankC(VRAM_C_SUB_BG);
    }
    if (keyPressed & KEY_B)
    {
      iprintf("Now arm9 is in the infinite loop");
      *((vu32*)0x027FFE04) = (u32)0xE59FF018;    // ldr pc, 0x027FFE24
      *((vu32*)0x027FFE24) = (u32)0x027FFE04;    // Set ARM9 Loop address
      asm volatile("swi 0x00\n");  // Soft reset
      iprintf("Error");
    }
    touchXY=touchReadXY();
    iprintf("\x1b[10;0HTouch x = %04X, %04X\n", touchXY.x, touchXY.px);
    iprintf("Touch y = %04X, %04X\n", touchXY.y, touchXY.py);
  }
  return 0;
}

_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#145795 - Lick - Thu Nov 22, 2007 4:11 pm

Check out the source code of rebootlib?
_________________
http://licklick.wordpress.com

#145796 - knight0fdragon - Thu Nov 22, 2007 4:39 pm

damn it, I forgot to disable the IRQ, what a waste of 3 hours lol
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206