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++ > Assignment of Global vars to .bss section??? Newbie !!!!

#587 - notron - Wed Jan 08, 2003 10:11 pm

Following is part of the linker map from a small test program I compiled with G++. I allocated a Decode buffer <DecodeBufr> of a size of 64000 bytes ( decimal not hex). This buffer would exceed the size of iwram on the GGBA which is defined as 32k = 32768d bytes. However, the linker has assigned this bufr to iwram anyway. Doesn't this exceed the actual availlable size of IWRAM???
Code:

COMMON         0x03000000        0x4 /cygdrive/e/gba/devkitadv/bin/...../libc.a(sbrkr.o)
                                  0x0 (size before relaxing)
                0x03000000                errno
                0x03000004                .=ALIGN(0x4)
 .bss           0x03000004     0xfa0c .\Debug\MOM_GBA.o
                0x0300000c                DecodeBufr
                0x03000004                screen_seg
                0x0300fa0c                g_pImage
                0x03000008                mouse_list_blank
 .bss           0x0300fa10       0x1c /cygdrive/e/gba/devkitadv/bin/...../libgcc.a(__main.o)
 .bss           0x0300fa2c        0xc /cygdrive/e/gba/devkitadv/bin/...../libgcc.a(unwind-dw2-fde.o)
 .bss           0x0300fa38        0x4 /cygdrive/e/gba/devkitadv/bin/...../libc.a(syscalls.o)
                0x0300fa3c                __bss_end=.
                0x0300fa3c                __bss_end__=.

.data           0x0300fa3c      0x78c load address 0x0827cc3c
                0x0300fa3c                __data_start=L(.)


Am I missing something ( Typical NEWBIE question huh?).
_________________
MysticX is The Defender

#595 - Touchstone - Wed Jan 08, 2003 10:33 pm

Sir, your array surely exceed the size of internal workram but the linker doesn't know about it. How could he ever know. :) If you want that large arrays you better move the BSS segment to external workram or create your own section, put that section in ext wram and tell the linker you want your huge array in that new sweet 256k section.
_________________
You can't beat our meat

#608 - notron - Wed Jan 08, 2003 11:09 pm

Touchstone, Thanks once again to you for helping out this newbie. Since the linker in Devkitadv was smart enough to know the beginning addresses of all the sections of the GBA, I thought it was smart enough to calculate the size of each section. Stupid Newbie mistake againa, duh!

Anyway, I thank you very much for your comment. Now I know that I have to keep track of the memory allocations myself. I found the tutor code on Devrs that shows how to force a variable to be allocated to a specific section and will do that next!

My next step will probably be to write a little memory mgt routine that keeps a set of tables in iwram to mgt memory allocated in Ewram.
_________________
MysticX is The Defender

#624 - ampz - Thu Jan 09, 2003 1:00 am

You can either set it up as two different sections (linker scripting... ugh..) or just do the ugly trick and hardcode the largish buffer to extram, and keep bss in intram. ;-)

#669 - notron - Thu Jan 09, 2003 4:39 pm

Ampz,

I agree on the linker scripts. At this point, I already tried and "died" screwing with linker scripts. I'm leaving that for later on the learning curve. For now, I am using the default linker script in G++ ( GCC) and using a __attribute__ override in my code to place stuff in various sections.

Since Iwram works really good in 32 bit mode, I am using it for pointers and using Ewram for all working variables. Seems to work pretty good so far.
_________________
MysticX is The Defender