C0 code type: Safe registers?

Started by spunit262, November 07, 2008, 05:17:13 AM

Previous topic - Next topic

spunit262

Not active but may still sporadically make codes.
(ooo)
``´´

brkirch

#1
No, you need to look at the code handler source to figure out the safe registers.  Or, if you want to write codes that will always work, even if the code handler is changed, you can construct a stack frame and use that to save and restore the registers.  For example, this will allow you to safely use registers r2-r31:
stwu r1,-0x80(r1)
stmw r2,8(r1)
<your code goes here>
lmw r2,8(r1)
addi r1,r1,0x80
blr

spunit262

I decided to actuly look though the code now that I'm better at hacking and this is what I found.

r0 safe
r1 Stack pointer
r2 Table of Contents (TOC) pointer
r3 safe
r4 not safe
r5 safe
r6 ba
r7 gr addresses
r8 code execution status
r9 safe
r10 safe
r11 safe
r12 safe
r13 not safe (reserved)
r14 safe
r15 code line address
r16 not used
r17 safe
r18 safe
r19 safe
r20 po
r21-r31 unknowen

r4 would be safe if it weren't for this
_hook_execute:
mr r18,r4 #r18 = 0YYYYYYY
rlwinm r4,r4,3,0,28 #r4  = NNNNNNNN*8 = number of lines (and not number of bytes)
bne- cr4,_hook_addresscheck #if sub code type != 0
bne- cr7,_skip_and_align

_execute:
mtlr r15
blrl

_skip_and_align:
>> add r15,r4,r15
addi r15,r15,7
rlwinm r15,r15,0,0,28 #align 64-bit
b _readcodes


But really r3-r12 should all be safe, if it followed the powerPC calling conventions
http://www.nersc.gov/vendor_docs/ibm/asm/linkage_convent.htm
Not active but may still sporadically make codes.
(ooo)
``´´

dcx2

This is a really old post, but in case anyone finds it...you should heed brkirch's warning in the post above.  The registers changed.

http://wiird.l0nk.org/forum/index.php/topic,5622.msg55892.html#msg55892