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

Mac OS ARM Native reaches ELF entry #769

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

niko1point0
Copy link

Reaches entry and then stops, the recompiler comes next

Copy link
Contributor

@squidbus squidbus left a comment

Choose a reason for hiding this comment

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

Overall this is good enough to get to ARM entry but a bit incomplete and untested, particularly the address space changes could have an impact or might need more modifications. I think you should really make some initial progress with getting an ARM translator running and then PR this stuff once its verified to be a sound base, just to validate that everything here is correct.

CMakeLists.txt Outdated
# Reserve system-managed memory space.
target_link_options(shadps4 PRIVATE -Wl,-no_pie,-no_fixup_chains,-no_huge,-pagezero_size,0x4000,-segaddr,TCB_SPACE,0x4000,-segaddr,GUEST_SYSTEM,0x400000,-image_base,0x20000000000)
# Using x86_64 (ARM by default if not set)
if (CMAKE_OSX_ARCHITECTURES)
Copy link
Contributor

Choose a reason for hiding this comment

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

You will need to check more than just CMAKE_OSX_ARCHITECTURES because it may be compiled natively on an Intel Mac. Simplest option I think would be to move the logic added to externals/CMakeList.txt for ffmpeg to this file and use the ARCHITECTURE variable to see if ARCHITECTURE STREQUAL "x86_64"

Copy link
Author

Choose a reason for hiding this comment

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

Done

#define Crash() __asm__ __volatile__("int $3")
#elif __aarch64__
#define Crash() ;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably have an actual implementation.

Copy link
Author

Choose a reason for hiding this comment

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

Done


#else

return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should have an alternate implementation or at least a TODO note.

Copy link
Author

Choose a reason for hiding this comment

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

Done

#else
// ARM
static inline u64 FencedRDTSC() {
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here for actual implementation or TODO.

Copy link
Author

Choose a reason for hiding this comment

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

Done

ASSERT_MSG(ret != MAP_FAILED, "mmap failed: {}", strerror(errno));
} else {
int ret = mprotect(reinterpret_cast<void*>(virtual_addr), size, prot);
ASSERT_MSG(ret == 0, "mprotect failed: {}", strerror(errno));
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the below in Unmap will need a closer look to make sure the behavior is correct, I put it together for you quick to get things going but I'm not sure it's good enough to go upstream.

Copy link
Author

@niko1point0 niko1point0 Sep 5, 2024

Choose a reason for hiding this comment

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

Actually no, this part was @squidbus who has more experience with the memory, so I trust that it's correct. Feel free to test though

[Edit] I just realized it was you that said the message, this was in the mem.patch file you gave me

Copy link
Contributor

Choose a reason for hiding this comment

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

That's... me though.

void* Linker::TlsGetAddr(u64 module_index, u64 offset) {
void* Linker::TlsGetAddr(u64 module_index, u64 offset)
{
#ifdef __x86_64__
Copy link
Contributor

Choose a reason for hiding this comment

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

You should probably just stub GetTcbBase() for now if anything, not the whole thing here.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -107,7 +119,9 @@ void Linker::Execute() {
}
}

#ifdef __x86_64__
SetTcbBase(nullptr);
Copy link
Contributor

@squidbus squidbus Sep 4, 2024

Choose a reason for hiding this comment

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

Instead of stubbing out SetTcbBase calls it should probably just have an stub function to call for now, it's going to need to be set up somehow for ARM translated code to access. Ditto for the other cases of this.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@georgemoralis georgemoralis marked this pull request as draft September 26, 2024 08:48
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