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

IOS: Handle ES_Launch more accurately #4906

Merged
merged 1 commit into from Feb 27, 2017

Conversation

leoetlino
Copy link
Member

[Depends on #4896.]

This commit fixes ES_Launch to work mostly the same as the real IOS (except temporary, internal files such as /sys/launch.sys and title handling; the latter will be handled in a future PR).

First of all, this adds two IOS functions, which correspond to two IOS syscalls: 0x41 (boot_ppc) and 0x42 (boot_ios).

  • boot_ios() writes the new version to 0x3140, loads the new kernel, which then proceeds to reinit IPC and load modules as part of its boot process. Note that this doesn't include writing to any of the other constants in the 0x3100 region. In Dolphin, this is implemented by changing the active IOS version variable, writing to 0x3140 and resetting all devices. This has the same effect as the real syscall.

  • The other syscall, boot_ppc(), writes code to the EXI boot buffer, pokes all constants to memory before bootstrapping the PPC with a binary from the NAND. We skip the low level stuff and just load the DOL to memory (and set the PPC's PC to 0x3400), which is essentially what IOS does.

The other change is mostly related to how ES_Launch is handled.

With a real IOS, if the launched title type is 00000001 (system) and the title is not 1-2 (System Menu), ES calls boot_ios().

Otherwise, ES handles the launch as a PPC title. It reads the TMD to determine the required IOS version. If it is the same, boot_ppc() is called directly. If not, ES saves the title to launch to the NAND before launching the new IOS. After the new IOS has finished booting, it will notice the flag and then launch the requested title.

What this commit does is really just implement this logic into IOS HLE. The result is a fix for a regression introduced by SetupMemory, where reloading an IOS would have overwritten some OS constants. This fixes booting games from the disc channel.

@ichee
Copy link

ichee commented Feb 13, 2017

Dolphin crashes on loading Wii System Menu.

@leoetlino
Copy link
Member Author

What version are you using? The only supported system menu is 4.3, currently. Older versions are not always supported because we are missing values from older system menu IOSes.

@ichee
Copy link

ichee commented Feb 13, 2017

This pr, and wii system menu is 4.3U from a complete nand dump. Also removed sysconf file.

@ichee
Copy link

ichee commented Feb 13, 2017

Broken by 4896.

@JMC47
Copy link
Contributor

JMC47 commented Feb 13, 2017

Can confirm. Happening here too.

@leoetlino
Copy link
Member Author

I missed the fact that IOS writes some values when it starts. Issues should be fixed now.

@ichee
Copy link

ichee commented Feb 13, 2017

Defaults to EUR region and gives disc error when trying to boot from Disc Channel.

disc

Also, when accessing system settings, gives error for unavailable address.

sys_settings

@leoetlino
Copy link
Member Author

Is it working on master? I'm not sure if that's related.

@ichee
Copy link

ichee commented Feb 13, 2017

Working as of 5.0-2507.

@ichee
Copy link

ichee commented Feb 13, 2017

Also creating EU formatted Gamecube mem cards when loading from wii system menu.

@leoetlino
Copy link
Member Author

Fixed in #4896 and rebased. Thanks for the report.


#include "Common/CommonTypes.h"

namespace AES

This comment was marked as off-topic.


namespace AES
{
std::vector<u8> Decrypt(const u8* key, u8* iv, const u8* src, u32 size);

This comment was marked as off-topic.

std::copy(&tmd[entry_offset + 0x01E8], &tmd[entry_offset + 0x01E8 + 2], iv.begin());
// The content index is used as IV (2 bytes); the remaining 14 bytes are zeroes.
std::array<u8, 16> iv{};
iv[0] = (content.index >> 8) & 0xFF;

This comment was marked as off-topic.

@leoetlino
Copy link
Member Author

@lioncash These were actually just moved from DiscIO/ES, but I've fixed them anyway (in #4896). I'll rebase this PR after #4896 gets merged.

@ichee
Copy link

ichee commented Feb 13, 2017

Confirmed working normally now.

@JMC47
Copy link
Contributor

JMC47 commented Feb 23, 2017

Is there any other changes required for this? I'd like to get the disc-channel working again :)

@JMC47
Copy link
Contributor

JMC47 commented Feb 27, 2017

The required changes for this one to be merged are done, so, if anyone can review/merge this one, we can get the disc channel working again.

This commit fixes ES_Launch to work mostly the same as the real IOS
(except temporary, internal files such as /sys/launch.sys and title
handling; the latter will be handled in a future PR).

First of all, this adds two IOS functions, which correspond to two
IOS syscalls: 0x41 (boot_ppc) and 0x42 (boot_ios).

boot_ios() writes the new version to 0x3140, loads the new kernel,
which then proceeds to reinit IPC and load modules as part of its
boot process. Note that this doesn't include writing to any of the
other constants in the 0x3100 region.
In Dolphin, this is implemented by changing the active IOS
version variable, writing to 0x3140 and resetting all devices. This
has exactly the same effect as the real syscall.

The other syscall, boot_ppc(), writes code to the EXI boot buffer,
pokes all constants to memory before bootstrapping the PPC with a
binary from the NAND.
We skip the low level stuff and just load the DOL to memory (and set
the PPC's PC to 0x3400), which is essentially what IOS does.

The other change is mostly related to how ES_Launch is handled.

With a real IOS, if the launched title type is 00000001 (system) and
the title is not 1-2 (System Menu), ES calls boot_ios().

Otherwise, ES handles the launch as a PPC title. It reads the TMD
to determine the required IOS version. If it is the same, boot_ppc()
is called directly. If not, ES saves the title to launch to the NAND
before launching the new IOS. After the new IOS has finished booting,
it will notice the flag and then launch the requested title.

What this commit does is really just implement this logic into IOS HLE.
The result is a fix for a regression introduced by SetupMemory,
where reloading an IOS would have overwritten some OS constants.
This fixes booting games from the disc channel.
@Helios747 Helios747 merged commit 7ac95c2 into dolphin-emu:master Feb 27, 2017
@leoetlino leoetlino deleted the es-launch branch February 27, 2017 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants