WDC816CC and farmalloc
Posted: Thu Apr 18, 2024 8:49 am
I am struggling to get farmalloc to work using WDC's linker and C compiler and I suspect it's more of a linker problem than a farmalloc problem.
I have the 'C' code:
Compiled and linked using:
farmalloc initially returns $00000000 (a zero value 32bit pointer) which doesn't make sense as I would expect the first return to be somewhere above $0012f111. As it loops it allocates out successive pointers for a little less than 64KB before executing a BRK instruction. Which also doesn't make sense as I would expect it to be able to allocate about 850KB before it can't any more.
The WDC documentation indicates:
The example allocates 128KSo I would expect to be able to allocate out more than 64KB.
The sharp eyed among you will have already noticed that heap_start is not the same as far_heap_start however if I use heap_start and heap_end then I get the following linker error:
And at this point I should mention I am compiling for the Large memory model (using -ml) and linking against the Large standard and math libraries (-lcl -lml).
~~far_heap_end and ~~far_heap_start are definitely referenced int the cl.lib file. So I think the WDC documentation is incorrect in their example.
If I look at the generated main.lst file I can see that ~~far_heap_start and ~~far_heap_end are correctly externally defined
and the linker seems to link them into cl.lib.
Has anyone managed to use farmalloc before (I think so) and if so please could you post how you did it! I don't know if I'm an idiot or if farmalloc really is broken.
I have the 'C' code:
Code: Select all
void* far_heap_start = (void*)0x12f111;
void* far_heap_end = (void*)0x1fffff;
void main(void)
{
void* pvBackground;
for (;;)
{
pvBackground = farmalloc(100);
...
}Code: Select all
wdc816cc.exe -bs -DUSING_816 -ml -wr -wu -so -sp -lt -pb -pp -px -o Main.obj Main.c
wdcln.exe -C10000 -D20000 -g -t -sz -HIE -obin\Video.hex Main.obj -lcl -lml
The WDC documentation indicates:
Quote:
Code: Select all
void *heap_start = (void * )0x28000, *heap_end = (void * )0x48000;The sharp eyed among you will have already noticed that heap_start is not the same as far_heap_start however if I use heap_start and heap_end then I get the following linker error:
Code: Select all
Undefined symbol: ~~far_heap_end
Undefined symbol: ~~far_heap_start
~~far_heap_end and ~~far_heap_start are definitely referenced int the cl.lib file. So I think the WDC documentation is incorrect in their example.
If I look at the generated main.lst file I can see that ~~far_heap_start and ~~far_heap_end are correctly externally defined
Code: Select all
701 ;void* far_heap_start = (void*)0x12f111;
702 data
703 xdef ~~far_heap_start
704 ~~far_heap_start:
705 00:0000: 11 F1 12 00 dl $12F111
706 00:0004: ends
707 ;void* far_heap_end = (void*)0x1fffff;
708 data
709 xdef ~~far_heap_end
710 ~~far_heap_end:
711 00:0004: FF FF 1F 00 dl $1FFFFF
712 00:0008: ends
Has anyone managed to use farmalloc before (I think so) and if so please could you post how you did it! I don't know if I'm an idiot or if farmalloc really is broken.