flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [bug] fasmg: unable to get uninitialized area contents

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 4166
Location: vpcmpistri
bitRAKE 30 Jul 2023, 21:44
If an area has at least one initialized byte, I am able to get the complete contents of the area. Yet, if the complete area is uninitialized then g.k328 returns: Error: address out of range.

The smallest code to produce the error:
Code:
virtual at Reserved.BASE
Reserved::
;       db -1 ; no longer an error, 17 byte contents retrieved.
        rb 16
end virtual

Reserved.BASE:
        contents AreaContent Reserved ; error when no initialized data    
It happens with "load contents:$-$$ from $$" - outside of CALM - seems to be general 'feature' of area.

My present work-around is to examine $%%, but I would like to load the string of zero bytes.

Initially, I thought is was a design choice. Yet, later I realized if even the first byte is defined the whole area can be retrieved - which makes it seem more like an error.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 30 Jul 2023, 21:44
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4166
Location: vpcmpistri
bitRAKE 30 Jul 2023, 22:18
bitRAKE wrote:
My present work-around is to examine $%%
... actually, that doesn't work. Instead I create a conditional byte at start of area.
Code:
FIX_BUG         := 0
USE_CALM        := 0

virtual at Reserved.BASE
Reserved::
        if FIX_BUG
                db -1
        end if
end virtual

Reserved.BASE:
virtual Reserved
        rb 16 ; bug only happens when the whole area is uninitialized
end virtual

if USE_CALM
        contents AreaContent Reserved
else
        load contents:sizeof Reserved from Reserved:Reserved.BASE
end if

db contents

calminstruction(target) AreaContent? area*
        local string
        load string, area: 0, sizeof area
        publish target, string
end calminstruction    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 30 Jul 2023, 22:18
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 31 Jul 2023, 06:29
Loading the uninitialized portion was not supposed to be correct, I think it's missing an error message in the partially-initialized case.
Post 31 Jul 2023, 06:29
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4166
Location: vpcmpistri
bitRAKE 31 Jul 2023, 07:16
So, the intended workflow would be to create an extra initialized byte at end of area, then load the area except that byte?

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 31 Jul 2023, 07:16
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 31 Jul 2023, 09:45
Or you can store 0 into the last uninitialized byte, it initializes the whole block then.
Post 31 Jul 2023, 09:45
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4166
Location: vpcmpistri
bitRAKE 31 Jul 2023, 13:42
Is there a way to know when an area has trailing undefined space?

I get the concept that this trailing data is undefined. Yet, it seems like it's protecting a corner case?
Code:
virtual at _Data.BASE
_Data::
        db 0
        db ?
        db 1
        db ?
end virtual

_Data.BASE:
load contents:1 from _Data:_Data.BASE + 0
db contents
load contents:1 from _Data:_Data.BASE + 1
db contents
load contents:1 from _Data:_Data.BASE + 2
db contents
load contents:1 from _Data:_Data.BASE + 3
db contents    
... even though the second byte is undefined, this only errors on the last byte. It would seem more consistent to error on all undefined data or none. What is so special about this last byte? What problem does it solve to not be able to read it? The error is there to prevent something unexpected from happening.

In my particular case I can't know if trailing uninitialized space exists or not. For example, struct. Writing an extra byte is fine.
Code:
; add a defined byte to force trailing undefined data to zeroes
calminstruction(target) AreaContent? area*
        local string, line
        arrange line, =virtual area
        assemble line
        arrange line, =db -1
        assemble line
        arrange line, =end =virtual
        assemble line
        load string, area: 0, sizeof area - 1
        publish target, string
end calminstruction    
For the case where it's known to be a purely uninitialized area, I can just use the size.

I do like that I can read an empty area and output nothing. It makes empty abstractions collapse without additional bookkeeping.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 31 Jul 2023, 13:42
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 31 Jul 2023, 14:02
Check the $@ symbol.
Post 31 Jul 2023, 14:02
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4166
Location: vpcmpistri
bitRAKE 31 Jul 2023, 19:16
Thank you, that is exactly what I was missing.
Code:
struc (contents) AreaContent area*
        virtual area
                if $@ = $
                        load contents.db:$-$$ from area:$$
                        contents.rb = 0
                else
                        load contents.db:$@-$$ from area:$$
                        contents.rb = $-$@
                end if
        end virtual
end struc    
... how I just glaze over paragraphs of the manual sometimes. Embarassed
(I'm going to blame the heat on this one - damn, it's been hot here.)

I did create a markdown version of the manual. Easier to read on mobile and click-copy code fragments.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 31 Jul 2023, 19:16
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 02 Aug 2023, 10:51
After re-examining this bug I realized you were right, this should be the other way around (to not signal an error in either case). Some of my own sources were relying on the ability to load the contents of partially initialized section.

And the fix appears very simple then. I hope this sorts it out.
Post 02 Aug 2023, 10:51
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4166
Location: vpcmpistri
bitRAKE 02 Aug 2023, 18:04
Many perspectives seem valid to me - viewing the virtual as just another output stream (reusing the same logic) -- all the way to -- having virtual as completely different type. I can even imagine a version without a default output stream, but I know you are on a migration path and not wandering around like a vagrant.

I'd like to try spending a whole day just using particular features - I think that would be challenging, but at the same time would force me to open my mind to possibilities that might not appear in the normal course of work. Of, course it's the wrong way. Just a little amusement.

(Of course, I've done a little of that already. Very Happy)

Thank you.
Post 02 Aug 2023, 18:04
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 02 Aug 2023, 20:57
Something similar I attempted is to implement as many as possible of fasmg's built-in directives in form of CALM instructions. A large portion of the language can be re-created this way already, so it's conceivable that a simpler core reduced to CALM functionalities could be enough to construct a fasmg-compatible assembler with set of headers just like I've done it for fasm 1 compatibility. But I don't pursue the idea seriously, it's not really justifiable, just a fun thought experiment.
Post 02 Aug 2023, 20:57
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 03 Aug 2023, 08:28
...although removing x86-centric data directives and size constants from the core could be a reasonable thing to do. They are easy to reconstruct with CALM now.
Post 03 Aug 2023, 08:28
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.