gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > asm adr and BSS section not working.

#168234 - FluBBa - Thu Apr 16, 2009 9:43 am

After a couple of hours I finally found out that using a BSS section and the adr (semi) opcode doesn't work in the latest DevKitARM (gcc bug?).

Doing something like:
Code:

   .arm
   .align 4
   .section .text
;@----------------------------------------------------------------------------
Sound_reset:
;@----------------------------------------------------------------------------
   stmfd sp!,{lr}
   adr r0,SN76496_0
   bl SN76496_reset         ;@ sound
   ldmfd sp!,{lr}
   bx lr
;@----------------------------------------------------------------------------
   .section .bss
SN76496_0:
   .space 72

r0 is loaded with the current PC and not with the address of SN76496_0.
Using ldr r0,=SN76496_o works as expected and is the right way to do it, but using adr should at least give a warning and probably an error.
_________________
I probably suck, my not is a programmer.

#168237 - olimar - Thu Apr 16, 2009 12:31 pm

FluBBa wrote:
After a couple of hours I finally found out that using a BSS section and the adr (semi) opcode doesn't work in the latest DevKitARM (gcc bug?).

Not a bug. Since it's in a different section, it can only be resolved at link time. Labels for ADR must be resolvable by the assembler (in the same section and not external). The reason for this is ADR gets translated to ADD r0, pc, #immediate (possibly a shifted immediate) which the linker doesn't know what to do with... the immediate needs to be figured out by the assembler.

FluBBa wrote:
r0 is loaded with the current PC and not with the address of SN76496_0.
Using ldr r0,=SN76496_o works as expected and is the right way to do it, but using adr should at least give a warning and probably an error.

Agreed (notice it does throw an error on ADR to externs though).

#168240 - Dwedit - Thu Apr 16, 2009 6:05 pm

Converting an emulator from SDT to GCC by hand?
It gets really tedious really quick, especially if you are trying to use register relative equates. GCC just doesn't support them.

So all the old code like "ldr r0,some_global" or something needs to be re-expressed as "ldr r0,[r10,#some_global]", where "some_global" is the difference between r10 and the equate's memory address.
Make a macro, like "ldr_" so that you can continue to use stuff very similar to the old code, so instead of having r10 and # everywhere, you just use "ldr_ r0,some_global".
Also need to do that for str, adr, adrl, and byte-sized, halfword-size, and conditional variations of each instruction.

You also need to change the way maps are declared...

this example map:
MAP 0,r10
var_1 # 4
var_2 # 4
byte_0 # 1
byte_1 # 1
halfword_0 # 2

becomes:
_map_address_ = 0
var_1 = _map_address_
_map_address_ = _map_address_ + 4
var_2 = _map_address_
_map_address_ = _map_address_ + 4
...

But we can simplify this with macros:

start_map 0
_m_ var_1,4
_m_ var_2,4
...


The source code conversion tool I made looks in header files for MAPS, and automatically adds an underscore to all instructions which use an equate defined inside a MAP. It also rewrites the map declaration to use macros to define each variable. It also does much more...
So it automatically changes the map, and also changes the "ldr r0,var_1" to "ldr_ r0,var_1". You still need to provide the macros, but they've already been written and are found in the goomba color GCC version.

So don't convert by hand, get some tools to help out.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#168242 - FluBBa - Thu Apr 16, 2009 7:38 pm

The SN76496 core was allready rewritten to use r0 as base for each instance of itself, but I have your macros for some other parts. I'm porting Green Beret right now and most stuff seem to work except I can't get good sound on the DS no matter how I try with MaxMod... So do one have to write everything by hand to get it to work correctly :-P

Edit: Just saw this in the source to maxmod (regarding structs in asm):
Code:

.struct 0
mms_rate:   .space 4
mms_len:   .space 4
mms_function:   .space 4
mms_format:   .space 4
mms_timer:   .space 4
mms_manual:   .space 1
mms_size:

_________________
I probably suck, my not is a programmer.