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++ > ewram & sbss question

#37715 - edwdig - Tue Mar 15, 2005 7:47 am

What I'm trying to do is allocate an unitialized array of structures within EWRAM. I'm using DevKitARM_R11, and this is what I'm doing:

static Sprite Sprites[MAX_SPRITES] __attribute__ ((section (".ewram")));

If I do this, everything works fine. The downside to this approach being that space for the array is allocated within the ROM image. So I figured I'd change ewram to sbss, which theoretically should have the same result, only with a smaller ROM size.

When I try to run the game with that change made, the game just doesn't work right. Sprites behavior simply becomes unpredictable. I'm assuming there is some kind of memory usage conflict. No where else in my code do I explicitly use EWRAM. Could it be a stack conflict? I'm also using Krawall - could the conflict be there?

#37726 - wintermute - Tue Mar 15, 2005 12:11 pm

could you paste the output from your mapfile

#37731 - sasq - Tue Mar 15, 2005 2:18 pm

Maybe the array gets cleared in the ROM-case but not BSS ?

#37763 - edwdig - Wed Mar 16, 2005 12:15 am

I did two builds, with the only difference being whether the struct mentioned before is placed in ewram or sbss. The full map files are 83k. Here are the ewram related sections. A diff shows no differences in the map files other than in this area. I trimmed off the ewram1-9 sections, as there isn't anything in there.

Map file with data in ewram:

Code:

.ewram          0x02000000     0x6274 load address 0x080f9cf8
 *(.ewram)
 .ewram         0x02000000     0x3ffc game.thumb.o
 .ewram         0x02003ffc     0x2278 krawall-16k-60-medium.lib
                0x02004cb2                _private_00066
                0x020048ac                _private_00006
                0x020050b8                _private_0005d
                0x020050b4                _private_0005c
                0x020050ba                _private_0005b
                0x02006274                . = ALIGN (0x4)
                0x080fff6c                __ewram_overlay_lma = (__ewram_lma + SIZEOF (.ewram))

.sbss           0x02006274        0x0
 *(.sbss)
                0x02006274                . = ALIGN (0x4)
                0x02006274                __ewram_end = .
                0x02006274                __ewram_overlay_start = .

.ewram0         0x02006274        0x0 load address 0x080fff6c
 *(.ewram0)
                0x02006274                . = ALIGN (0x4)
                0x080fff6c                __load_start_ewram0 = LOADADDR (.ewram0)
                0x080fff6c                __load_stop_ewram0 = (LOADADDR (.ewram0) + SIZEOF (.ewram0))


Map file with data in sbss:

Code:

.ewram          0x02000000     0x2278 load address 0x080f9cf8
 *(.ewram)
 .ewram         0x02000000     0x2278 krawall-16k-60-medium.lib
                0x02000cb6                _private_00066
                0x020008b0                _private_00006
                0x020010bc                _private_0005d
                0x020010b8                _private_0005c
                0x020010be                _private_0005b
                0x02002278                . = ALIGN (0x4)
                0x080fbf70                __ewram_overlay_lma = (__ewram_lma + SIZEOF (.ewram))

.sbss           0x02002278     0x3ffc
 *(.sbss)
 .sbss          0x02002278     0x3ffc game.thumb.o
                0x02006274                . = ALIGN (0x4)
                0x02006274                __ewram_end = .
                0x02006274                __ewram_overlay_start = .

.ewram0         0x02006274        0x0 load address 0x080fbf70
 *(.ewram0)
                0x02006274                . = ALIGN (0x4)
                0x080fbf70                __load_start_ewram0 = LOADADDR (.ewram0)
                0x080fbf70                __load_stop_ewram0 = (LOADADDR (.ewram0) + SIZEOF (.ewram0))

#37764 - edwdig - Wed Mar 16, 2005 12:25 am

sasq wrote:
Maybe the array gets cleared in the ROM-case but not BSS ?


Just did a quick memset() on the array, and that seems to fix the issue. It really doesn't explain the behavior I was seeing (bullets going straight across the screen would just randomly abruptly stop without being near anything else), but ok, if that makes it work I'll take it.

I'm really not sure why that makes a difference here though, as this code used to use malloc for about 6 months until I just recently changed it to allocate the memory at compile time. Theoretically malloc should also being giving me uninitialized EWRAM, but yet that worked fine.

Should sbss be initialized to zero? I would assume it would, since its really still an uninitialized global variable, which C would normally zero init.