Hacking Coding vWii 3-core support - everything you need to know.

Maxternal

Peanut Gallery Spokesman
OP
Member
Joined
Nov 15, 2011
Messages
5,210
Trophies
0
Age
40
Location
Deep in GBAtemp addiction
Website
gbadev.googlecode.com
XP
1,709
Country
The bit shift isn't needed... I've been using that hook code on xbox 360 for ages now, and it works as-is (like I said, reliable.) But yeah, they basically re-use the &3 bits for flags in some instructions because of 4 byte alignment for instructions.

notice...
range 0-0x1FFFFFC (0x3FFFFFC sign extended, negative bit 0x2000000) link bit 0x1

A DWORD/u32 is unsigned, subtraction of two u32 when the value being subtracted is greater than the value being subtracted from is by no means guaranteed to give you a value that can just be stuffed into the sign extend mask. Notice the dest/cur are reversed in subtraction of the backwards branch vs. the forward branch, this is to ensure a positive value as a result (instead of using int and a bunch of casting), which gets or'd with the bit that indicates negative/sign extend. To make this function totally safe/complete it really should have a range check before assembling the instruction, but in the case of a bootloader or something, you should know before using it if it will be effective as there are really no feed back mechanisms other than <crash><unplug from wall>.

Anyway, do what you want with the code. I posted it because I use it regularly and know absolutely it is reliable. About the most you'll get me to agree to is that the mask can be simplified from 0x3f to 0x1f.

edit:
bonus round... in a 32bit address system, is 0x80000000 address negative zero, or what? xD (it's much more work to mask that bit out and convert to int than to just deal with it as a pair of positive u32)
Okay, I see how that works now. Thanks for clarification ;)
 
  • Like
Reactions: Ray Lewis

Maxternal

Peanut Gallery Spokesman
OP
Member
Joined
Nov 15, 2011
Messages
5,210
Trophies
0
Age
40
Location
Deep in GBAtemp addiction
Website
gbadev.googlecode.com
XP
1,709
Country
bonus round... in a 32bit address system, is 0x80000000 address negative zero, or what? xD (it's much more work to mask that bit out and convert to int than to just deal with it as a pair of positive u32)
hmm, I think I had learned that the msb was supposed to always be the sign bit in 2's compliment numbers and that (because of overflow) adding a negative number ended up the same as adding the same binary value as an unsigned number

example:
-1 + 1 = 0
0xFFFFFFFF + 0x00000001 = 0x00000000
(adding 1 to unsigned 0xFFFFFFFF would overflow to 0 anyhow so it ends up the same.)

so even though that works fine casting it and masking it out, it may not be necessary.
I'd have to test that, though.


EDIT : that does mean, though, now that I think about it, that branching from 0x100 and branching from 0x81330100 for core are probably too far apart for them to both branch into the same address so I might have to have 2 copies of the same code for each ... or manually load an address into the link register and run the "blr" instruction to fake returning from a function :ph34r: in order to get that far.

EDIT2 : wait, 0x100 isn't actually in mem2 or mem1 according to wiibrew
http://wiibrew.org/wiki/Memory_Map so how is it supposed to be accessible as a reset vector? :unsure:
 

Maxternal

Peanut Gallery Spokesman
OP
Member
Joined
Nov 15, 2011
Messages
5,210
Trophies
0
Age
40
Location
Deep in GBAtemp addiction
Website
gbadev.googlecode.com
XP
1,709
Country
  • Like
Reactions: Ray Lewis

Maxternal

Peanut Gallery Spokesman
OP
Member
Joined
Nov 15, 2011
Messages
5,210
Trophies
0
Age
40
Location
Deep in GBAtemp addiction
Website
gbadev.googlecode.com
XP
1,709
Country
(it's much more work to mask that bit out and convert to int than to just deal with it as a pair of positive u32)
Even though that works fine casting it and masking it out, it may not be necessary.
I'd have to test that, though.
I just took advantage that nice little site that [user]shuffle2[/user] used and tested this out and GOOD NEWS, it looks like the masking and casing isn't really necessary. The result is the same either way, with or without casting and with or without the mask.
http://codepad.org/6NOTcxr6
http://codepad.org/CeMqSAGh
(with only a minor adjustment since that site apparently doesn't like "bool")
 
  • Like
Reactions: izzydeank

the_randomizer

The Temp's official fox whisperer
Member
Joined
Apr 29, 2011
Messages
31,284
Trophies
2
Age
38
Location
Dr. Wahwee's castle
XP
18,969
Country
United States
I edited. Check op; still some "to do" but this is awesome. Every time I look here I see progress and great help given. I realized my post was wayyyyy premature.

Even so.....there are some coding geniuses on here....and here I was all ready to read up on PPC ASM and just plain ASM. :ph34r:

Its nice, because you can post your code online and it executes it for you. Plus you can share it easily.
Didn't even know about that site. Nice!
 

Ray Lewis

Banned!
Banned
Joined
Dec 30, 2012
Messages
1,518
Trophies
0
XP
419
Country
United States
0x100 is a physical address. 0x80000100 is the corresponding virtual address. When a PPC processor takes an interrupt, including reset, address translation is initially off.
Thanks for stopping by Comex. There has been a LOT of changes.
 

marcan_troll

Well-Known Member
Member
Joined
Sep 30, 2009
Messages
133
Trophies
0
XP
519
Country
United States
At this rate, you might even know what you're doing by the time the WiiU2 comes out!

(I *am* a troll, but it *does* take longer than a couple of years to go from having trouble with two's complement arithmetic to being able to start a serious port of an SMP operating system to a new platform. Keep trying, though, and you'll get there, just don't expect it to be in time to be relevant for the Wii U).
 

BIFFTAZ

Well-Known Member
Member
Joined
Jul 26, 2010
Messages
596
Trophies
1
XP
846
Country
At this rate, you might even know what you're doing by the time the WiiU2 comes out!

(I *am* a troll, but it *does* take longer than a couple of years to go from having trouble with two's complement arithmetic to being able to start a serious port of an SMP operating system to a new platform. Keep trying, though, and you'll get there, just don't expect it to be in time to be relevant for the Wii U).

Ouch..
 

the_randomizer

The Temp's official fox whisperer
Member
Joined
Apr 29, 2011
Messages
31,284
Trophies
2
Age
38
Location
Dr. Wahwee's castle
XP
18,969
Country
United States
At this rate, you might even know what you're doing by the time the WiiU2 comes out!

(I *am* a troll, but it *does* take longer than a couple of years to go from having trouble with two's complement arithmetic to being able to start a serious port of an SMP operating system to a new platform. Keep trying, though, and you'll get there, just don't expect it to be in time to be relevant for the Wii U).

Alrighty then, guess that's a sign to work harder then. ;)
 

Crewman

Active Member
Newcomer
Joined
May 9, 2013
Messages
42
Trophies
0
Age
44
XP
142
Country
Gambia, The
The only problem is that an absolute branch can only work within the first 64mb of memory addresses, max (16mb with the bit shift :( ) so I'd have to check again the mem addresses for mem1 and mem2 from the PPC side to see how limiting that would really be.

There is a work around. Load the absolute address to the LR register and then do a blr to jump.
If you look out for a Op Code for blr there is non because it is a virtual instruction, that means it is a special case of the bclrl instruction.
So you have to use the code of the bclr instruction:

bclr:
bit 0-5:
0b01011 -> Op Code
bit 6-10:
1z1zz -> branch always. z means bit will be ignored and can set to what ever you want
bit 11-15:
00000 -> Condition register used. You can probably set this to what ever you want because we branch always
bit 16-20:
00000 -> always has to be 0
bit 21-30:
0000010000 -> always has to be like this
bit 31:
1 -> if this bit is set, then the effective address of the instruction following the branch instruction is placed into the link register.

so you have to load 0x4E800021 into memory

btw. lis and li are also virtual instructions, so as you have to set the LR register, you have to use addis and addi instead

At this rate, you might even know what you're doing by the time the WiiU2 comes out!
Any help is welcome, I think we are all no experts in this.
 

comex

Well-Known Member
Newcomer
Joined
Jan 21, 2007
Messages
56
Trophies
0
XP
243
Country
United States
For the record, the reason libogc is copyright infringement is not that the hardware or general operation of the SDK was reverse engineered, but that large numbers of individual SDK functions were reverse engineered and translated directly into C.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: I really don't want to buy this fap tab...