Repository navigation
Add SPTM Emulator - #1
niklassheth wants to merge 23 commits into
Conversation
ADevWithAnIdea
left a comment
There was a problem hiding this comment.
Took a brief glance, on the whole, looks good to me, just a few general things (specifics left inline):
- comments need human review
- new files are gpl2
- there's the sptm emulator itself (sptm.py and the sptm/whatever.c stuff) and the scaffolding that goes around it in hv.c, hv_exc.c, whatever, the sptm emulator can be a monolithic comment but the stuff around it should be broken out, unfortunately this is likely quite a bit of human labor on your part but otherwsie review is difficult
- how bad would it be to prototype an all C sptm emulator? this would remove a lot of complexity, and tbh it seems pretty one shottable with codex
| self.p.mask32(base + off, 0x3ff, (data | 0xf) & ~(0x80000400)) | ||
| _pmgr[base + off] = (data & 0xfffffc0f) | ((data & 0xf) << 4) | ||
| addr = base + off | ||
| if not shadow_pmgr: |
There was a problem hiding this comment.
why is this necessary exactly? so we allow the xnu cpustart why? why do we need this setting, and if so it should be its own commit.
There was a problem hiding this comment.
toss the comment, change the spdx license identifer to gpl 2 only (i'll update the license globally, and same for all new files) and say that this is the boot handoff. you also need to describe how the python half of the emulator talks to the C endpoints. TBH I'm somewhat in favor of just rewitig the whole emulator in C and tossing the python entirely, still undecided here, but it removes the need for the python/c communication entirely
There was a problem hiding this comment.
oh also i basically didn't look at the file itself at all because idrc as long as it works
| parser.add_argument('-l', '--logfile', type=pathlib.Path) | ||
| parser.add_argument('--fake-disp0', action='store_true', | ||
| help='Alias every T8132 dart-disp0 SID 0 mapping to one ' | ||
| 'of 8192 read-only zero pages') |
There was a problem hiding this comment.
is this a leftover from the dcp hang after login debugging? if so is this still needed/functional/whatever?
There was a problem hiding this comment.
also if so this should be its own commit
There was a problem hiding this comment.
I just got display out working so this is no longer needed! This will be removed
There was a problem hiding this comment.
make this its own separate commit, first in the series, just call it add more sysregs or something
| #include "cpu_regs.h" | ||
| #include "display.h" | ||
| #include "gxf.h" | ||
| #include "hv_sptm.h" |
There was a problem hiding this comment.
nothing from here is actually used? if i'm reading this right
| reg_set(CNTHCTL_EL2, | ||
| CNTHCTL_EL1NVVCT | CNTHCTL_EL1NVPCT | CNTHCTL_EL1TVT | CNTHCTL_EL1PCTEN); | ||
| /* | ||
| * Guarded M4 guests use the architectural virtual timer as the |
There was a problem hiding this comment.
shorten the comment, and why not
set CNTHCTL_EL2, CNTHCTL_EL1TVT)
if apple sysregs unlocked:
set the rest
makes more sense to me than the clear, but ti's a minor detail
| int hv_map_hook(u64 from, hv_hook_t *hook, u64 size); | ||
|
|
||
| /* T8140 CPU/ACC/CPM write guard (no-op on other SoCs); see hv_t8140.c. */ | ||
| /* CPU/ACC/CPM write guards for hypervisor-managed power state. */ |
There was a problem hiding this comment.
hypervisor-managed is wrong, it causes el2 serrors
| ram_size, MAIR_IDX_NORMAL, PERM_RX_EL0, | ||
| handoff_start, handoff_size); | ||
|
|
||
| /* |
There was a problem hiding this comment.
this is entirely for the hv? if so we should gate it on the hv
There was a problem hiding this comment.
this just looks like yuka's patchset? it should be its own separate thing, not squashed with yoru sptm emulator
There was a problem hiding this comment.
Good catch, there are some upstream changes I pulled in and accidentally squashed. I'm not sure if they're even needed, but it would be good to rebase on upstream since some t8132 changes were made
There was a problem hiding this comment.
yeah I'll do this likely tomorrow, i'll pull in upstream changes to main, and change the license/readme, and then you can rebase then
|
Oh also I didn't review the sptm emulator itself at all, or the larger general HV changes, especially hv_exc.c, there's just a lot of them and i'm currently short on time |
|
whoops forgot to select the appropriate regions, apologies about that, knock wood most of it should be codexable anyways (review the comments and commit breakdown manually) |
|
Thanks for the detailed review! On moving the emulator into C, Python constructs the initial environment, but all of the endpoints are already in C. So C and Python don't need to communicate after boot. The current code with a bunch of added proxy endpoints can definitely be improved, but I think it's a good setup as long as we only support one SPTM version at a time. I can't think of a good reason to keep 26.6 support around after 27.0 comes out anyways |
This is extremely incorrect, we're going to keep 26.6 around forever because we're going to bless 26.6 as the M4/A18 Pro firmware version. We'll bless a different 27.X version whenever the M5 SKUs are fixed. We can assume the number of versions to support is small (one per soc generation). By communication, I don't mean runtime communication, but things like where stuff lives in memory. m1n1 has a very clear THIS IS NOT ABI STABLE promise so it's not a huge deal |
|
Oh also can you add a commit to just disable sapt universally? that should be its own thing and applies for hv or for no hv, should be a pretty trivial patch, just if m4+ or a18 pro + check memory size, find sapt region, zero the proper range |
|
Oh also, add a Signed off by, just run git commit -s when you actually make the commit to have it added automatically |
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Program the guarded guest event-stream state through CNTKCTL_EL12 and rescale XNU's 24 MHz event index to the architectural counter frequency. Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Rearm the physical EL2 timer after guest deadline changes, time-offset updates, and host tick programming so the emulated Apple deadline is serviced on time. Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
Locate XNU AMX capability symbols and retain their valid state through kernel initialization. Once userspace shared regions are nested, suppress AMX in the kernel and commpage capability policy. Also configure SMCR_EL2 for M4 SME guests so primary and secondary CPUs expose the maximum streaming vector length. Assisted-By: OpenAI Codex (GPT-5.6 Sol) Signed-off-by: Niklas Sheth <hi@niklassheth.com>
|
Closing in favor of GravityLinux/bootloader#8 |
No description provided.