Skip to content

Remove current_exception_sp0. - #34

Merged
qwandor merged 1 commit into
mainfrom
exceptions
Dec 4, 2025
Merged

Remove current_exception_sp0.#34
qwandor merged 1 commit into
mainfrom
exceptions

Conversation

@qwandor

@qwandor qwandor commented Dec 4, 2025

Copy link
Copy Markdown
Collaborator

Switching spsel manually appears to be unnecessary. Exception vectors are always called with SP_ELx, and the spsel is restored from SPSR on eret.

Switching spsel manually appears to be unnecessary. Exception vectors
are always called with SP_ELx, and the spsel is restored from SPSR on
eret.
@m4tx

m4tx commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

For posterity:

Exception handler pseudocode contains the following:

noreturn func AArch64_TakeException(target_el : bits(2), exception_in : ExceptionRecord,
                                    preferred_exception_return : bits(64), vect_offset_in : integer)
begin
    // ...
    PSTATE.SP = '1';

    // ...
    BranchTo{64}(VBAR_ELx()[63:11]::vect_offset[10:0], BranchType_EXCEPTION, branch_conditional);
    // ...
end;

eret instruction pseudocode contains the following:

AArch64.ExceptionReturn(bits(64) new_pc_in, bits(64) spsr,
                        boolean is_texit, boolean illegal_psr_state)
    // ...
    SetPSTATEFromPSR(spsr, illegal_psr_state, is_texit);
    // ...
SetPSTATEFromPSR(bits(N) spsr_in, boolean illegal_psr_state, boolean is_texit)
    // ...
    if illegal_psr_state then
        // ...
    else
        // ...
        PSTATE.SP  = spsr<0>;
    // ...

Hence, exception handler will always set spsel to 1 on enter and spsr<0> on exit (assuming eret is executed).

@qwandor
qwandor merged commit 17e58a0 into main Dec 4, 2025
4 checks passed
@qwandor
qwandor deleted the exceptions branch December 4, 2025 13:06
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