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.

ASM > syntax question

#164263 - moonlightcheese - Fri Oct 24, 2008 7:55 pm

i'm looking at this code snippet from prex, trying to reverse engineer the steps necessary to load ELF binaries and i don't get the syntax for the name## label and the #SYS_##name label. what do those hash signs do there? the rest of it i can read...

Code:
#define SYSCALL0(name) \
   .global name; .align; \
name##: \
   stmfd sp!, {r4, r5, lr}; \
   mov r4, #SYS_##name; \
   ldr r5, =0x200007c; \
   add lr, pc, #2; \
   mov pc, r5; \
   ldmfd sp!, {r4, r5, pc};

also what does =0x200007c mean?

edit: i think i figured out the first question although i'm still don't know the exact syntax. looks like SYS_msg_send and other defines exist in the system call header file and it looks like the hashes do some kind of variable name replacement. still not sure exactly how it works...

#164264 - Kyoufu Kawa - Fri Oct 24, 2008 8:28 pm

I'm not sure about the ## thing, but it reminds me of a trick with string concatenation in the C preprocessor. In short, I think writing SYSCALL0(Foo) would result in a Foo label and the statement "mov r4, #SYS_Foo;".

As for your second question, that seems like a straigthforward "load from this specific address". Ofcourse, it's unclear what that is.

#164267 - strat - Sat Oct 25, 2008 12:57 am

ldr r5, =0x200007c

This actually stores the address 0x200007c in another rom address and loads r5 with the contents of that address. It would assemble to something like this:

200029a: 4c05 ldr r5, [pc, #20]

20 bytes up you'd find

20002b0: 007c ; shows up as false code
20002b2: 0200 ; in a disassembly

Arm/Thumb can't load immediate values greater than 0xFF. That's a feature of the assembler, not legal machine code.