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.

C/C++ > Multiboot problems

#36670 - Vertex - Sun Feb 27, 2005 9:58 pm

Hi!
Code:
#include "gball.h"

#define MULTIBOOT volatile const u8 __gba_multiboot;
MULTIBOOT

int main(void)
{
   u16 c = 0;
   
   SetMode(MODE_3 | BG2_ENABLE);
   for(c = 0; c < 38400; c++)
   {
      VideoBuffer[c] = (31 << 10);
   }
   
   while(1);
}


and
Quote:
path=E:\Dev\GBA\DevkitARM\devkitadv-r5-beta-3\bin
gcc -Ttext=0x02000000 -o main.elf main.c
objcopy -O binary main.elf main.mb.gba
del *.elf
pause


GCC compile this code correct, but I can't boot this with my GBA.

I think, the problem is, that on address 0x02000000 is the instruction "b $020000e4". But on other bootable roms, the istruction is every "b $020000c0".

I can send my rom with F2APowerWriter correctly and start it, but with my own send-tool, I can only sending roms with "b $020000c0" correctly.

Can anyone help me?

cu olli

#36672 - tepples - Sun Feb 27, 2005 10:04 pm

When you send the 192 byte header, you have to copy the first four bytes out of the ROM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#36673 - Vertex - Sun Feb 27, 2005 10:30 pm

Ahhhhh, the boatable roms I have test it, have the 192 byte header includet *run against the wall*

When will update my send tool, do you think, I must send only the 192 byte header + ROM, or do I must send like this:

Code:
const u8 Header [] = {
 46,0,0,234,36,255,174,81,105,154,162,33,61,132,130,10, // 16
 132,228,9,173,17,36,139,152,192,129,127,33,163,82,190,25, // 16
 147,9,206,32,16,70,74,74,248,39,49,236,88,199,232,51, // 16
 130,227,206,191,133,244,223,148,206,75,9,193,148,86,138,192, // 16
 19,114,167,252,159,132,77,115,163,202,154,97,88,151,163,39,
 252,3,152,118,35,29,199,97,3,4,174,86,191,56,132,0,
 64,167,14,253,255,82,254,3,111,149,48,241,151,251,192,133,
 96,214,128,37,169,99,190,3,1,78,56,226,249,162,52,255,
 187,62,3,68,120,0,144,203,136,17,58,148,101,192,124,99,
 135,240,60,175,214,37,228,139,56,10,172,114,33,212,248,7,
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,49,150,0,0,0,0,0, // 24
 0,0,0,0,0,240,0,0
};

typedef struct {
  u32 reserve1[5];      //
  u8 hs_data;           // 20 ($14) Needed by BIOS
  u8 reserve2;          // 21 ($15)
  u16 reserve3;         // 22 ($16)
  u8 pc;                // 24 ($18) Needed by BIOS
  u8 cd[3];             // 25 ($19)
  u8 palette;           // 28 ($1c) Needed by BIOS - Palette flash while load
  u8 reserve4;          // 29 ($1d) rb
  u8 cb;                // 30 ($1e) Needed by BIOS
  u8 reserve5;          // 31 ($1f)
  u8 *startp;           // 32 ($20) Needed by BIOS
  u8 *endp;             // 36 ($24) Needed by BIOS
  u8 *reserve6;         // 40 ($28)
  u8 *reserve7[3];      // 44 ($2c)
  u32 reserve8[4];      // 56 ($38)
  u8 reserve9;          // 72 ($48)
  u8 reserve10;         // 73 ($49)
  u8 reserve11;         // 74 ($4a)
  u8 reserve12;         // 75 ($4b)
} MBStruct;

MBStruct mp;

void SetMultiboot()
{
   *(u16 *)MB_CNT = 0;
}

u16 xfer(u16 send)
{
   *(u16 *)SIOMLT_SEND = send;
   *(u16 *)SIOCNT = 0x2083;

   while(*(vu16 *)SIOCNT & 0x80)
   {}
   return (*(vu16 *)SIOMULTI1);
}

WaitForGBA()
{
   u16 i;

   do
   {
      i = xfer(0x6202);
   }
   while (i != 0x7202);

   i = xfer(0x6100);
}

SendHeader()
{
   u16 i;

   xfer((Header[1] << 8) + Header[0]);
   xfer((Header[3] << 8) + Header[2]);

   for(i=2; i<96; i++)
      xfer((Header[i*2+1] << 8) + Header[i*2]);

   i = xfer(0x6202);
}

SendROM()
{
   u8 palette;
   u8 debug = 1;
   u16 i;
   u16 key;
   u32 length;

   mp.cb = 2;
   mp.pc = 0xd1;
   mp.startp = (u8 *)&Client [0xc0];
   length = sizeof(Client) - 0xc0;
   length = (length + 15) & ~15; /* 16 byte units */
   if (length < 0x1c0) length = 0x1c0;
   mp.endp = (u8 *)&Client [0xc0] + length;

   palette = 0xc1;
   mp.palette = palette;

   i = xfer(0x6300+palette);
   i = xfer(0x6300+palette);

   mp.cd[0] = i;
   mp.cd[1] = 0xff;
   mp.cd[2] = 0xff;

   key = (0x11 + (i & 0xff) + 0xff + 0xff) & 0xff;
   mp.hs_data = key;

   i = xfer(0x6400 | (key & 0xff));

   // Execute BIOS routine to transfer client binary to slave unit
   asm volatile (
      " ldr r0,=mp\n"
      " mov r1,#1\n"
      " swi 0x250000\n"       //NOTE!!!!! Use 0x250000 for ARM C Compiler mode.
      :  // Outputs       // 0x25 here will only work for Thumb mode.
      :  // Inputs
      : "r0","r1","r2","r8","r9","r10","r11","r12"     // Regs crushed & smushed
      );
}


cu olli

#36674 - tepples - Sun Feb 27, 2005 11:31 pm

Vertex wrote:
Ahhhhh, the boatable roms I have test it, have the 192 byte header includet *run against the wall*

When will update my send tool, do you think, I must send only the 192 byte header + ROM, or do I must send like this:

Code:
SendHeader()
{
   u16 i;

   xfer((Header[1] << 8) + Header[0]);
   xfer((Header[3] << 8) + Header[2]);

   for(i=2; i<96; i++)
      xfer((Header[i*2+1] << 8) + Header[i*2]);

   i = xfer(0x6202);
}

The first four bytes of the header sent to the GBA must come from Client[] rather than Header[], as they contain the jump instruction.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.