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 > Reset to GBA mode?

#121752 - ttabbal - Wed Mar 14, 2007 2:51 pm

I'm sure it has to have been discussed here, but I'm coming up empty on the search. I found this ASM code on NDSTek (IIRC) that I inlined into C for ease of use.

Code:

void bootGBA()
{
    asm(".arm");
    asm("mov r2, #0x40");
    asm("swi 0x1F0000");
}


Problem is, it doesn't work. I don't get the GBA logo or anything. Did I miss something?

#121754 - Lick - Wed Mar 14, 2007 3:32 pm

You should check out Loopy's homebrew firmware source. Google "hbfirmware".
_________________
http://licklick.wordpress.com

#121757 - ttabbal - Wed Mar 14, 2007 4:22 pm

Thanks for the tip! I've downloaded it and will go over the source.

#121778 - josath - Wed Mar 14, 2007 8:29 pm

Here's what I call and it works fine for me (resets into GBA mode):
Code:
                mov    r2, #0x40
                ldr    r12, =0x11B8      @ call some routine in the bios
                bx     r12


This has to be called on the arm7 btw.

Also, I never liked inlining asm code. I'd suggest using a .s file. For example:

Code:
@@@@ asmstuff.s
.arm
.section        ".text"
.align  4

.global GoGBAMode
.func GoGBAMode
GoGBAMode:
                mov    r2, #0x40
                ldr    r12, =0x11B8      @ call some routine in the bios
                bx     r12
.endfunc

.end


In your main file:
Code:
extern void GoGBAMode(void);


If you are using C++, don't forget the 'extern "C" {...}' wrapper thing.

#121779 - ttabbal - Wed Mar 14, 2007 8:36 pm

Hey josath, thanks a bunch! I suspect part of my problem was also that I was running it from the ARM9. Grrr... I guess I'll have to write it on the 7 or use IPC.

Any particular reason you don't like inline ASM? Not that I disagree, I don't have enough ASM experience to debate it, just wondering.

#122119 - GrizzlyAdams - Sat Mar 17, 2007 2:33 am

Here is part of the code I'm using to get into GBA mode. The missing parts are just the FIFO stuff I'm using. I'm sure you can figure out how to use the FIFO already.

ARM7 Code:
Code:
void gbaMode() {
        vu32* startCtrl = (vu32*)0x027FFCE4;

        if (((*startCtrl >> 3) & 0x01) == 0x01)         // Bottom screen enable
        {
                writePowerManagement(0, PM_BOTTOMLIGHT | PM_SOUND);
        } else {
                writePowerManagement(0, PM_TOPLIGHT | PM_SOUND);
        }
         
        // Restart in gba mode
        __asm (".arm\n"
        "mov    r2, #0x40\n"
        "swi    0x1F0000\n"
        );
}


ARM9 Code:
Code:
void gbaMode() {
        u16 clear = 0x0000;
        u32 *VRAMA = (u32 *)0x06000000;
        u32 *VRAMB = (u32 *)0x06020000;
        u32 *VRAMC = (u32 *)0x06040000;
        u32 *VRAMD = (u32 *)0x06060000;
        vramSetMainBanks(       VRAM_A_MAIN_BG, VRAM_B_MAIN_BG,
                VRAM_C_MAIN_BG, VRAM_D_MAIN_BG);
        dmaFill(3, VRAMA, clear, 256*256*2);
        dmaFill(3, VRAMB, clear, 256*256*2);
        dmaFill(3, VRAMC, clear, 256*256*2);
        dmaFill(3, VRAMD, clear, 256*256*2);
        vramSetMainBanks(       VRAM_A_MAIN_BG, VRAM_B_MAIN_BG,
                VRAM_C_ARM7, VRAM_D_ARM7);

        if(PersonalData->_user_data.gbaScreen) {
                lcdMainOnBottom();
        }
        REG_EXEMEMCNT = (0xa08f);
        FIFOSend(IPC_CMD_GBAMODE);
        CheckFIFO();

        for(;;);
}

#122192 - HyperHacker - Sat Mar 17, 2007 8:16 pm

Can you be sure that personal data will never be overwritten during your program's execution? I'd copy the info you need to global variables at startup to be safe.
_________________
I'm a PSP hacker now, but I still <3 DS.

#129769 - spinal_cord - Sat May 26, 2007 11:15 am

GrizzlyAdams - I have tried using you r code, but I'm getting noise in the border, is there anything I can do to avoid that.

Also is ther a way to boot a slot-1 card?
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#130118 - tondopie - Thu May 31, 2007 1:39 am

use lick's reboot lib to boot to a SLot-1 device.
_________________
Development Blog: http://teendev.org
Homebrew Podcast: http://homebrewcast.net
Web Design: http://xtendesign.net

#130156 - Lick - Thu May 31, 2007 10:53 am

spinal_cord: yes there is, but it involves re-inserting the slot-1 card and after that you have to do decryption and stuff, very complicated.

tondopie: my rebootlib unfortunately 1) only works on homebrew devices 2) doesn't work on all homebrew devices 3) doesn't do any GBA mode stuff 4) doesn't clear memory before reseting.
But it does what it does.
_________________
http://licklick.wordpress.com

#130277 - tondopie - Fri Jun 01, 2007 10:03 pm

spinal_cord: look in hbfirmware... it will be hard for you to use if you are using PAlib... stick to less advanced functions.
_________________
Development Blog: http://teendev.org
Homebrew Podcast: http://homebrewcast.net
Web Design: http://xtendesign.net