I see that globals explicitly initialized to some value get initialized thru a copy in crt0... but I don't get how/when other globals are initialized.
I mean, doesn't C require that every global is initialized to 0 when not explicitly set to a value?
Last edit: sverx 2015-04-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Some platforms do the zeroing in the BIOS / loader, so it is left out of the default crt0.s (I guess for historic reasons, maybe the original developers of the z80 port were using such a platform). On platforms where this doesn ot happen, you need to zero the memory in your custom crt0.s (e.g. libcv, http://colecovision.eu/ColecoVision/development/libcv.shtml for the ColecoVision).
Philipp
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK. So, since you're not doing it in the provided z80 crt0 I guess you should write somewhere in the docs that globals won't be initialized if you don't do it explicitly.
Thanks for your help :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Instead of documenting this I think we should change it first. The default should be to zero the memory for uninitialized globals/statics. And if you don't need that, you can remove it in your custom crt0.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I agree, but how can you do that? I mean I have this code added to my crt0:
xor a ; clear RAM (to value 0x00)
ld hl,#0xc000 ; by setting value 0
ld (hl),a ; to $c000 and
ld de,#0xc001 ; copying (LDIR) it to next byte
ld bc,#0x1ff0 ; for 8 KB minus 16 bytes
ldir ; do that
which of course works, but assumes RAM is at 0xC000 and 8 KB big, but that's of course platform dependent...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I see that globals explicitly initialized to some value get initialized thru a copy in crt0... but I don't get how/when other globals are initialized.
I mean, doesn't C require that every global is initialized to 0 when not explicitly set to a value?
Last edit: sverx 2015-04-06
Some platforms do the zeroing in the BIOS / loader, so it is left out of the default crt0.s (I guess for historic reasons, maybe the original developers of the z80 port were using such a platform). On platforms where this doesn ot happen, you need to zero the memory in your custom crt0.s (e.g. libcv, http://colecovision.eu/ColecoVision/development/libcv.shtml for the ColecoVision).
Philipp
So you mean that actually if I declare a global like this:
it will be initialized but if I declare it like this:
it won't get initialized so actually it could end up with a bogus initial value if I don't provide a system to clear RAM in crt0?
Yes. It doesn't make much sense, but that's how it currently is for historical reasons.
Philipp
OK. So, since you're not doing it in the provided z80 crt0 I guess you should write somewhere in the docs that globals won't be initialized if you don't do it explicitly.
Thanks for your help :)
Instead of documenting this I think we should change it first. The default should be to zero the memory for uninitialized globals/statics. And if you don't need that, you can remove it in your custom crt0.
I agree, but how can you do that? I mean I have this code added to my crt0:
which of course works, but assumes RAM is at 0xC000 and 8 KB big, but that's of course platform dependent...
The linker provides symbols for location and length of of segments.
Philipp
P.S.: I'd write their names here, but Sourceforge markup keeps messing them up.