Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PowerPC arch. #29

Closed
wants to merge 1 commit into from
Closed

Conversation

maximumspatium
Copy link
Contributor

Below my first attempt at the PowerPC arch descriptor. It has some limitations described in the source.

The most difficult decision is the proper name for this arch. For the moment being, it describes the calling convention Apple borrowed from IBM and used in Mac OS until 2002.

Mac OS X, introduced around 2000, uses a similar calling convention in its Mach-O format. The most notably difference between them is the usage of R2:

  • in the old Mac OS and IBM, R2 holds the pointer to the data section descriptor ("TOC" - table of content, hence the name "RTOC" for R2). R2 will be passed around to each call and thus acts like an implicit parameter (SaBl recognizes this case automatically).
  • in Mach-O, R2 is considered a general purpose register while the program data is accessed differently (via position independent code).

What's the best solution to this problem? Two different archs ("ppc32-peff" and "ppc32-macho")?
Moreover, there is Linux PPC. I have no clue which calling convention is used there...

@pfalcon
Copy link
Owner

pfalcon commented Jan 31, 2018

Looks good!

The most difficult decision is the proper name for this arch.

Yeah, that's oftentimes the case ;-).

in Mach-O, R2 is considered a general purpose register while the program data is accessed differently (via position independent code).

Ok, is it used for e.g. param passing, or is it callee-saved register? Because otherwise, param filter would deal with it (i.e. it won't be treated as a param), and the difference seems to boil down just to naming - "r2" vs "rtoc". I guess you very well know that r2 can be used as rtoc, then using adhoc naming isn't of much benefit, and both cases above could be covered with just one SABl "arch", with "r2" as naming.

But well, ultimately, it's up to you how to name - I don't have experience with PowerPC, so can't suggest much there. (On a calm day it would be interesting to dig into PPC calling conv, but I'm not sure how soon I'd have that ;-) ).

@pfalcon
Copy link
Owner

pfalcon commented Jan 31, 2018

@maximumspatium, Of related note, I wonder if you might be interested in trying to enable PowerPC support in my another tool, ScratchABit: pfalcon/ScratchABit#39 . No hurries, just wonder if you're remotely interested, or have all your PowerPC disassembly needs covered. Thanks.



def call_ret(addr):
return {REG("r3")}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, how longlong's and double's are returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Apple's specs, any value larger than 4 bytes must be returned via memory. For that purpose, the left-most parameter (in other words, R3) must point to a memory location where the return value will be stored to.

The same rule is valid for more than 8 params and variadic functions. Params[8:] as well as variadic args must be passed on the stack.

Float & doubles will be returned in dedicated floating-point registers. I assume that floating-point isn't currently supported so I omitted them for the moment being.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, sounds good.

I assume that floating-point isn't currently supported

Yes, there's no any special support it.

@pfalcon
Copy link
Owner

pfalcon commented Feb 15, 2018

@maximumspatium : Let me know if you'd like to make any changes before this merged. Otherwise, I'd merge this, further changes can go later if needed.

@maximumspatium
Copy link
Contributor Author

Okay to merge.

@pfalcon
Copy link
Owner

pfalcon commented Feb 16, 2018

Merged, thanks!

@pfalcon pfalcon closed this Feb 16, 2018
@maximumspatium maximumspatium deleted the arch-ppc branch April 18, 2018 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants