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

Makes both stage1 and 2 as position independent executables #32

Merged
merged 3 commits into from
Jun 17, 2016

Conversation

gemarcano
Copy link
Contributor

These commits implement stage1 and 2 as position independent executables, meaning they can be placed at any address, and they should still run. Stage2 doesn't benefit from this too much (although this does mean it can easily be moved around now), but stage1 can now be moved without having to modify linker scripts if for some reason the key needs to change.

I have tested these changes on my o3DS. I tested stage1 relocation by changing the key being used to the old one and placing stage1 in the right place, but leaving everything else intact, which worked. It also works with the newer key. Stage2 I tested by simply changing the location in RAM where it was saved to and launched from. This also worked.

I would highly recommend this be tested by people with hardmods before being merged. I am not extremely confident in my understanding of PIC/PIE.

I also took the opportunity to try to improve the _start.s file in stage1, and the Makefiles.

Had to implement a memcpy replacement since PIC code is incompatible
with the default newlib used by devkitarm.
@@ -13,9 +13,19 @@
extern u8 screen_init_bin[];
extern u32 screen_init_bin_size;

static inline void* copy_memory(void *dst, void *src, size_t amount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a heads up, PIC code isn't compatible with the newlib standard library shipped with devKitARM, so I included a simple replacement for memcpy here.

-Fixed a bug in the GOT relocation in stage1 _start.s. Wrong base
address was being calculated.
-Refactored stage1 and stage2 _start.s files.
-Copied screen_init.c from dark_samus's repository, which was also
worked on by Aurora. Looks cleaner, works fine.
-Drew from changes cleaning up screen init from dark_samus's repository,
which also includes changes done by Aurora. Files affected include bits
of stage2 main.c, screen.h, and screen.c.
-In order to handle icache correctly, now flushing caches right before
jumping to the payload to make sure icache sees the data that has been
placed in memory.
@pixel-stuck
Copy link
Contributor

Tested on my console, werks

@mariogamer2
Copy link
Contributor

mariogamer2 commented Jun 15, 2016

In this case,what does "werk" mean?

@LunaDook
Copy link

@mariogamer2 Assume it was a grammatical error. He's saying it works on his device.

@mariogamer2
Copy link
Contributor

mariogamer2 commented Jun 16, 2016

Can anyone test this with dark-samus/AuroraWright fork? (don't want to take the risk....)

@jasondellaluce
Copy link
Owner

I tested this in my Old3DS, and it worked with no problems.
I'll wait some more confirmations, but i think that this pull request is legit.

@sykhro
Copy link

sykhro commented Jun 17, 2016

works on my end (new3ds)

@jasondellaluce jasondellaluce merged commit ae297e8 into jasondellaluce:master Jun 17, 2016
@gemarcano gemarcano deleted the PIC branch June 19, 2016 04:41
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.

6 participants