Page 1 of 1
clearing heap in djgpp
Posted: Tue Jul 26, 2005 11:45 am
by GLneo
hi all, i know thers some built in varables that define heap position but i can't seem to figure out how to zero out the heap???
Re:clearing heap in djgpp
Posted: Tue Jul 26, 2005 6:01 pm
by AR
Do you mean the .bss Section or the actual heap? The compiler shouldn't have any concept of what the heap even is, you will have to manually zero the memory once it's been allocated.
To zero the .bss, you'll need to modify your linker script so that you have something like:
Code: Select all
{
bss = .;
*(.bss)
bssend = .;
}
bsslength = bssend - bss;
Then in your opening Assembly code you would have something like:
Code: Select all
.extern bss
.extern bsslength
mov $bss, %edi /* I don't have my code or compiler on hand but this should be close enough to figure out */
mov $bsslength, %ecx
xor %eax, %eax
rep
stosb
You can also optimize by dividing by 4 in the link script (
bsslength = (bssend - bss) / 4;) and then using stosd to set 4bytes at a time instead of 1.
@Solar: My GAS (Cygwin i686-pc-elf 2.16.1) won't assemble STOSD, it accepts STOSB and STOSW but won't take STOSD [.code32], what have I done now?
Re:clearing heap in djgpp
Posted: Tue Jul 26, 2005 7:44 pm
by GLneo
thx that helped, stosd doesn't work for me ether??? stosw works so i used it
Re:clearing heap in djgpp
Posted: Wed Jul 27, 2005 6:27 am
by mkr
AR wrote:@Solar: My GAS (Cygwin i686-pc-elf 2.16.1) won't assemble STOSD, it accepts STOSB and STOSW but won't take STOSD [.code32], what have I done now?
Don't you mean 'STOSL' instead?
mkr
Re:clearing heap in djgpp
Posted: Wed Jul 27, 2005 6:45 am
by AR
That helps, bloody obvious solution again, comes from knowing both Intel and GAS Syntax assembly and being reasonably fluent in both.