Align inside BSS section

All 680x0 related coding posts in this section please.

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

tommo
Atariator
Atariator
Posts: 29
Joined: Mon Jan 29, 2018 6:00 pm

Align inside BSS section

Postby tommo » Wed May 15, 2019 10:28 am

Devpac 3 question:
How do you align inside the BSS section?

I want var_3 to align_16 relative to the BSS start.
( even = align 2 , long even = align 4 , etc)


example:

Code: Select all

   TEXT
      move.w   d0,d0
      ...
      cnop   0,16   (Align DATA segment)
   DATA
var      dc.w   1
      ...
      cnop   0,16   (Align BSS segment)
   BSS
var_2      ds.w   1
      ...
   <align_16>
var_3      ds.l   128
   END

User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 1681
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Align inside BSS section

Postby Cyprian » Wed May 15, 2019 11:03 am

if I'm not wrong, there is no way to align DATA or BSS to Long Word, due to the OS cares only about Word boundary alignment.
but you can align it on your own:

Code: Select all

   move.l   #var_3,D0
   addq.l   #4,D0
   and.w   #$FFFC,D0
   move.l   D0,A0
Lynx II / Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.appspot.com/

tommo
Atariator
Atariator
Posts: 29
Joined: Mon Jan 29, 2018 6:00 pm

Re: Align inside BSS section

Postby tommo » Wed May 15, 2019 12:10 pm

Cyprian wrote:... the OS cares only about Word boundary alignment.

That is correct, i use a little program that starts the main program on a align_16 base.

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2476
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Align inside BSS section

Postby charles » Wed May 15, 2019 12:34 pm

whats the EVEN command do ,
could u use it?
or
pad with zero's to self align ?
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 1681
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Align inside BSS section

Postby Cyprian » Wed May 15, 2019 12:45 pm

tommo wrote:
Cyprian wrote:... the OS cares only about Word boundary alignment.

That is correct, i use a little program that starts the main program on a align_16 base.

you can try to implement your own relocation code, that would allow you to place also DATA and BSS section on align_16 base.



charles wrote:whats the EVEN command do ,
could u use it?
or
pad with zero's to self align ?

EVEN ensures you that next data will be Word boundary aligned
Lynx II / Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.appspot.com/

User avatar
dhedberg
Atari God
Atari God
Posts: 1066
Joined: Mon Aug 30, 2010 8:36 am
Contact:

Re: Align inside BSS section

Postby dhedberg » Wed May 15, 2019 2:38 pm

tommo wrote:
Cyprian wrote:... the OS cares only about Word boundary alignment.

That is correct, i use a little program that starts the main program on a align_16 base.

So you're relocating code/data/bss? Would you mind sharing that piece of code?
Daniel, New Beat - http://newbeat.atari.org. Like demos? Have a look at our new Falcon030 demo and feel the JOY.

tommo
Atariator
Atariator
Posts: 29
Joined: Mon Jan 29, 2018 6:00 pm

Re: Align inside BSS section

Postby tommo » Wed May 15, 2019 3:52 pm

FOUND IT !

the * is the location where i am now.
then substract the BSS lokation from it.

then put empty spaces in place when not alighned.

so this looks like

Code: Select all

   BSS      ;(where BSS starts)
BSS      ;(a label is needed to indicate that)
   ...
   ifeq ((*-BSS)&1)^1   ;make even
   ds.b   1
   endc
   ifeq ((*-BSS)&2)^2   ;make long
   ds.w   1
   endc
   ifeq ((*-BSS)&4)^4   ;make alighn_8
   ds.l   1
   endc
   ifeq ((*-BSS)&8)^8   ;make alighn_16
   ds.l   2   
   endc

var_3   ds.l   128

should make a MACRO for it.

User avatar
dhedberg
Atari God
Atari God
Posts: 1066
Joined: Mon Aug 30, 2010 8:36 am
Contact:

Re: Align inside BSS section

Postby dhedberg » Wed May 15, 2019 3:57 pm

Hmm, does this really work? The aligning will take place during assembly, but when the resulting executable is loaded the Atari TOS can put it anywhere. The OS only guarantees that it starts at an even address. As far as I understand it, alignment on anything but word addresses requires relocating the code/data manually during runtime.
Daniel, New Beat - http://newbeat.atari.org. Like demos? Have a look at our new Falcon030 demo and feel the JOY.

mikro
Hardware Guru
Hardware Guru
Posts: 1992
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Align inside BSS section

Postby mikro » Wed May 15, 2019 4:16 pm

Daniel is correct, that works only on paper (computer screen ;-)), what is important is how the OS handles BSS segment (and it usually puts it on a word boundary, as mentioned).

tommo
Atariator
Atariator
Posts: 29
Joined: Mon Jan 29, 2018 6:00 pm

Re: Align inside BSS section

Postby tommo » Wed May 15, 2019 4:21 pm

dhedberg wrote:Hmm, does this really work? The aligning will take place during assembly, but when the resulting executable is loaded the Atari TOS can put it anywhere. The OS only guarantees that it starts at an even address. As far as I understand it, alignment on anything but word addresses requires relocating the code/data manually during runtime.
Yes it works, i tested it first, but this is better:

Code: Select all

MACRO   ALIGHN_16
   ifne (*-BSS)&1   ;make even
   ds.b   1
   endc
   ifne (*-BSS)&2   ;make long
   ds.w   1
   endc
   ifne (*-BSS)&4   ;make alighn_8
   ds.l   1
   endc
   ifne (*-BSS)&8   ;make alighn_16
   ds.l   2
   endc
   ENDM


It is true during debugging it is not aligned to a 16 bound addres.
but is IS aligned relative to the label. ( in this case BSS)

When started from a little program i already made that exacutes a program on a fixed alignment
this works.

Thanks everyone for thinking with me. :cheers:

for who is interested:
the 68060 has a cache that works with 4longs (called a line) at the time, so this is aligned to 16.

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2432
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Align inside BSS section

Postby lp » Wed May 15, 2019 4:36 pm

tommo wrote:FOUND IT !

the * is the location where i am now.
then substract the BSS lokation from it.

then put empty spaces in place when not alighned.

so this looks like


I have done something similiar with a macro in devpac when trying to optimize a program for the 030 caches. As some have stated alignment on anything but word addresses requires doing the loading and fix up yourself. I think that even applies to MiNT. I used a small program to load and fix it up.

tommo
Atariator
Atariator
Posts: 29
Joined: Mon Jan 29, 2018 6:00 pm

Re: Align inside BSS section

Postby tommo » Wed May 15, 2019 4:44 pm

dhedberg wrote:So you're relocating code/data/bss? Would you mind sharing that piece of code?
No, no relocating.

A program that shrinks its memorie to the alignment wanted.
Then it executes a program. (that gets placed after the shrunk memorie)
when the program is finished i comes back and it quits.

I think the shrinking also includes the already run code and all of the data and bss to maximize free memorie.

lp wrote: I used a small program to load and fix it up.
So, i am not the only one that had that thought... :D

So thanks again everyone who made the effort to think with me. :cheers:

wietze
Captain Atari
Captain Atari
Posts: 253
Joined: Fri Mar 01, 2013 10:52 pm

Re: Align inside BSS section

Postby wietze » Sat May 18, 2019 8:52 am

I would just use a pointer and align that pointer, then copy data/code to that pointer and use it.
Or is this too complicated?

User avatar
dhedberg
Atari God
Atari God
Posts: 1066
Joined: Mon Aug 30, 2010 8:36 am
Contact:

Re: Align inside BSS section

Postby dhedberg » Sat May 18, 2019 10:35 am

On the 030, code alignment becomes important as well due to the i-cache but sure, for the bss section it's just to align pointers. For data it could be a bit more work than just align and copy if the data contains pointers to data.
Daniel, New Beat - http://newbeat.atari.org. Like demos? Have a look at our new Falcon030 demo and feel the JOY.


Social Media

     

Return to “680x0”

Who is online

Users browsing this forum: No registered users and 1 guest