Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Winavr BSS END

Status
Not open for further replies.

iteration69

New Member
I've been trying to figure out how to find the __bss_end to be used in my code for quite awhile now. I can't figure it out so i'm asking for some help.

I noticed the linker script references the bss start and end but i can not get it to work in C source code.

I've tried all the names that work in other tools.
BSS_END, __bss_end, bssend, BSSEND, _BSSEND.
All of the above result in the same error

error: '__bss_end' undeclared (first use in this function)


Does anyone know how to reference the end of the .bss ?
 
Well if the"b" is a typo and it should be an "a" then it makes much more sense. That end is a place that most good programmers don't want to go.
 
Good one :)

No it's not a typo. The .bss is where certain types of variables are placed. There is an old trick to create static memory pools by using the memory between the .bss end and the stack. This saves .init code, program space and sram due to the manual management.

BUT we need to know where the .bss ends so that we do not clobber other variables.

Currently the only way i know to find the end is to open the list file, which is ok since i keep an eye on the compiler output so that it doesnt try to cheat. but it is not the proper way.... Hence the reason for asking
 
A missing include file?
Was bss_start called?
 
in other tools i've seen bss_Start. but i have not read anywhere that is exists in avr-gcc.

it does call .do_clear_bss_start

There are no missing files. Everthing builds fine, i simply do not how to reference the end of the .bss.

in other tools i can do int var = bss_end;
or a similar nomenclature is generally valid. I've read the compiler, linker, and the make manuals but did not see anything about referencing the end of the bss.

The map file shows the linker script using PROVIDE (__bss_start, .) Everything i have tried to reference this has produced an error.

If anyone has referenced the end of the bss with avr-gcc, I would appreciate the requirements(arguments, example etc) A citation in the documentation would be great.
 
Just a few mins ago i realized that __bss_end is not resolved untill linking. So that makes it external.
ie to get a ptr to out semi free mem.

extern __bss_end;

void somefunc(void)
{
volatile char *semi_free_mem = (char*) __bss_end;
}

I just cheked the list file and it appears to be working correctly. Once i verify it a little more i'll check back in. Keep i
n mind that the stack will approach __bss_end this is why i call it semi-free. As long as you keep an eye on your code
this makes for an easy way to allocate static memory blocks while keeping automatics -- automatic.

I'm still fairly new at C programming, for example 10-20k lines of C as compared to ~250,000 assembler. But i believe this method to be correct.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top