09 May 2019, 11:37 | #1 |
OCS forever!
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
|
DS directive - is it zeroed?
Hi,
I always assumed that DS.w type sections are zeroed in memory when in a CODE/DATA section. And that they were not zeroed in a BSS section. The devpac manual says "These directives will reserve memory locations and the contents will be initialised to zeros......except in the case of true BSS sections". In ASMOne/Pro there is a preference option for "DS Clear" but the manual says that outside of ASMOne (final exe) they will NOT be cleared. Is this a difference in assemblers or is it just the ASM one manual I'm misunderstanding and it's only talking about BSS sections? |
09 May 2019, 11:52 | #2 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
The devpac manual maybe means that in the case of CODE and DATA section the space reserved and zeroed with DS is actually present in the final file structure, while for BSS the allocation is left to the system. |
|
09 May 2019, 12:01 | #3 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
True BSS hunks are always zeroed.
If you use DS right in the middle of the code, it's like DC with a value of zero. However, there can be some empty space at the end of CODE/DATA sections. This means allocated area is bigger than actual contents : the extra data is considered like BSS. It's sometimes called CODE_BSS or DATA_BSS sections. This is supported only in V37+, or something like that. |
09 May 2019, 12:09 | #4 |
OCS forever!
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
|
Ok thanks that's what I'd assumed (although didn't realise BSS was zeroed). So what is the ASMOne "DS Clear" preference option talking about?
"DS Clear - If ON, ASM-One will clear BSS sections for you automatically. But remember, the Amiga will NOT clear BSS sections for you if you start your program outside ASM-One." That doesn't make sense if the system segment loader zeros it... |
09 May 2019, 12:18 | #5 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Yes this doesn't make sense.
Like meynaf explained there is a possible exception in the case of the DS directive used at the end of a section (CODE or DATA but this does not concern BSS). Unfortunately there is no standard among the various assemblers (you are lucky if is supported or there is a specific option). The structure of Amiga executable files includes an initial header where the number, type, amount and type of memory required by the various sections are specified. So the allocation is made immediately without taking into account the space actually on disk used by the section itself. If the section uses less space than the one initially declared then the final part can be used as a BSS space (call it DATA_BSS space..), but the assembler must have foreseen a similar use and refer to it adequately. In this case there is a substantial difference between KS1.x and KS2.0+. In the former case that space is NOT cleared by the system loader, in the latter YES. Last edited by ross; 09 May 2019 at 12:30. Reason: latter.. |
09 May 2019, 12:48 | #6 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
Yes, you should never assume BSS space is cleared. DS can be used in all sections, not just BSS.
Unfortunately on later Kickstarts, the OS interferes and clears them with a slow routine, when in fact you just wanted some workspace, which means you wouldn't need to clear it at all. And if you wanted it or part of it cleared, you'd like to do it with an optimal routine. It's not so nice to click a program, and just because it declared some BSS, there's a second of extra delay starting it, instead of opening right away. |
09 May 2019, 13:27 | #7 |
OCS forever!
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
|
I just did some tests in ASMOne in a normal CODE section.
Unless "DS Clear" is enabled then DS directives are not zeroed after assembling. So that's very different behaviour to devpac. Code:
SECTION test,code move.w #1,Data rts Data: ds.w 16 |
09 May 2019, 14:02 | #8 | |||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
BTW, the most frequent use case of DATA_BSS is Small Data, which is supported by a lot more tools. Quote:
The only thing the developer could do to allow DATA_BSS is to move uninitialized and zero space (usually DS and DC 0 directives) to the end of a code or data section and hope for a smart linker or output-module. What? Under AmigaOS, and most other sane operating systems, you definitely can! The only case where you might have to clear BSS yourself is when the target is some kind of development board, without any form of OS and executable file format (e.g. loading Motorola S-Records or other raw formats). Or are you talking about DATA_BSS space here? Quote:
|
|||
09 May 2019, 14:09 | #9 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
I was about to say: looks like a bug to me. But originally DS only means "Declare Storage" (uninitialized). This storage is certainly always 0 in a BSS section, but it is not necessarily 0 in initialized sections. "DS.B x" is more like "* = * + x" in ancient sources. It's just like most assemblers will zero it automatically, which makes it kind of a standard...
|
12 May 2019, 00:43 | #10 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
So AmigaDos 1.3 is insane.
No, you really need some way to allocate space without clearing it with a crap slow routine, and AmigaDOS provides that in all versions with Alloc. If I wrote a 4K I certainly wouldn't want anything to interfere just because I need the remaining 400K Chipmem for buffers. The same would certainly be true for any decompressor adding a BSS hunk. Performance would be absolutely through the floor and the decompressor would be made worthless by the OS if it did that. I think one has opposite views on this depending on whether you're on a slow computer or a fast one. So this has nothing to do with target platform or anything like that, it's just whether you'd like the OS to automatically do it for you, slowly, every time. It certainly shouldn't by default, is my view. |
12 May 2019, 12:30 | #11 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
As far as I remember, the MEMF_* flags are used in the hunk structure to specify section memory requirements. Could it be the case that this includes MEMF_CLEAR, so the executable itself can specify if it wants a section cleared or not?
|
12 May 2019, 12:59 | #12 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
If I'm not mistaken it's unfortunately an extension to the hunk structure that works exclusively with KS2.0+.
|
12 May 2019, 13:00 | #13 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Tested and yes, an extension that works exclusively with KS2.0+
Code:
value = read_uint32(f) hunk_type = value & 0x3FFFFFFF mem_flags = value & 0xC0000000) >> 29 if mem_flags == MEMF_CHIP | MEMF_FAST: mem_flags = read_uint32(f) & (1 << 30) mem_flags = mem_flags | MEMF_PUBLIC |
12 May 2019, 21:47 | #14 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Then you are talking about DATA-BSS hunks? Otherwise there is no difference for real BSS hunks between 1.3 and 2.0+.
And yes, 1.3 is insane, because that was a bug which 2.0 fixed. Quote:
|
|
13 May 2019, 20:49 | #15 | ||
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
phx: What bug?
Quote:
Quote:
~ Best practice is to use DCB/BLK for space that is to be initialized, and DS for space that should be uninitialized, i.e.: Code:
SECTION Screenbuffers,BSS_C Screen0: ds.l 320*256*5/32 Screen1: ds.l 320*256*5/32 So the manuals have nothing to do with the Kickstart behavior, because you understood the directive and used it correctly, so you're expecting junk in those buffers and will add code to clear it/fill it with your data. (Promise! ) I'm not sure what the meaning is with the extra clearing proposedly done on KS2+, but if so and you coded using best practice, the declared space is cleared twice. Last edited by Photon; 13 May 2019 at 21:18. |
||
13 May 2019, 21:37 | #16 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
If you're unhappy with this, use AllocMem. The error is in the interpretation of how a BSS section works. Only part that is not cleared is unused area of CODE/DATA sections, a bug present in 1.x that has been fixed in 2.0. |
|
13 May 2019, 23:06 | #17 | |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Quote:
|
|
13 May 2019, 23:13 | #18 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
But we just confirmed BSS hunks are not cleared on KS1.3.
The interpretation is perfectly clear. You add a BSS section to declare space that should be allocated at runtime, instead of bloating the exe. There is no handling of DS in CODE/DATA sections and hunks other than for the Assembler to convert them to DCB/BLK and bloating the exe. And that is exactly what actually happens, whatever preference the Assembler/Compiler has for it being cleared or not. So we're learning something here. What on earth do you mean by DS in CODE/DATA sections? Nobody who wants that means anything. Or perhaps they mean they shouldn't have forgotten to turn the DS into DCB/BLK. Catch my drift? A BSS section/hunk is a BSS section/hunk, not a CODE or DATA section/hunk. There's no need for a fourth type phx, it's just someone done gone and f'ed up the meaning provided in the first place; the reason for the existence of BSS sections/hunks. I really hope someone understands this. "Niklaus Wirth would not approve of implementations." And he knows a thing or two. |
13 May 2019, 23:53 | #19 | |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Quote:
It means extending the memory allocated beyond the size of the data. |
|
14 May 2019, 08:39 | #20 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
This is where the error lies - BSS hunks are cleared even on KS1.3. That some assemblers writers apparently didn't know, doesn't change the fact.
BSS hunks and unused areas at the end of CODE/DATA are two different things. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Issues with ORG directive (vasm + FS-UAE) | Maggot | Coders. Asm / Hardware | 15 | 05 September 2023 11:56 |
vasm basereg example directive | mcgeezer | Coders. Asm / Hardware | 7 | 18 November 2020 19:58 |
REPT directive in vasm | phx | Coders. Asm / Hardware | 8 | 01 October 2014 21:48 |
AsmOne even directive...? | pmc | Coders. General | 30 | 04 December 2009 09:33 |
Invalid Directive | Kimmo | support.WinUAE | 1 | 23 July 2004 11:23 |
|
|