{"record":{"id":"71a7c12561f22bbe","repo":"rust-embedded/rust-raspberrypi-OS-tutorials","slug":"should-not-be-here-use-of-sp-el0-in-el1-is-not-su","errorCode":null,"errorMessage":"Should not be here. Use of SP_EL0 in EL1 is not supported.","messagePattern":"Should not be here\\. Use of SP_EL0 in EL1 is not supported\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"20_timer_callbacks/kernel/src/_arch/aarch64/exception.rs","lineNumber":76,"sourceCode":"// Private Code\n//--------------------------------------------------------------------------------------------------\n\n/// Prints verbose information about the exception and then panics.\nfn default_exception_handler(exc: &ExceptionContext) {\n    panic!(\n        \"CPU Exception!\\n\\n\\\n        {}\",\n        exc\n    );\n}\n\n//------------------------------------------------------------------------------\n// Current, EL0\n//------------------------------------------------------------------------------\n\n#[no_mangle]\nextern \"C\" fn current_el0_synchronous(_e: &mut ExceptionContext) {\n    panic!(\"Should not be here. Use of SP_EL0 in EL1 is not supported.\")\n}\n\n#[no_mangle]\nextern \"C\" fn current_el0_irq(_e: &mut ExceptionContext) {\n    panic!(\"Should not be here. Use of SP_EL0 in EL1 is not supported.\")\n}\n\n#[no_mangle]\nextern \"C\" fn current_el0_serror(_e: &mut ExceptionContext) {\n    panic!(\"Should not be here. Use of SP_EL0 in EL1 is not supported.\")\n}\n\n//------------------------------------------------------------------------------\n// Current, ELx\n//------------------------------------------------------------------------------\n\n#[no_mangle]\nextern \"C\" fn current_elx_synchronous(e: &mut ExceptionContext) {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/blob/644474cc09f755249f9c55d99a5d1e07a2562fc7/20_timer_callbacks/kernel/src/_arch/aarch64/exception.rs#L58-L94","documentation":"current_el0_synchronous is the vector-table entry for synchronous exceptions taken at the current exception level when using SP_EL0, which this kernel does not support (it runs at EL1 with its own stack). The handler unconditionally panics. It exists only so that every vector slot is defined; reaching it means user-mode (EL0) execution or SP_EL0 use happened although the kernel never intends to support it.","triggerScenarios":"Taking a synchronous exception (e.g. SVC, instruction abort, data abort) at the current EL while SP_EL0 is the active stack pointer — i.e. code running in EL0 state or an explicit SP switch to SP_EL0 in EL1.","commonSituations":"Attempting to implement user-space processes before the kernel supports EL0, accidentally setting SPSel to 0 in early boot or context-switch code, or porting code that issues `svc` calls expecting syscall support that this tutorial kernel does not provide.","solutions":["Do not run code at EL0 or switch to SP_EL0; audit boot and context-switch code for `msr spsel, #0` and remove it.","If user-mode support is intended, replace this stub with a real EL0 synchronous handler (syscall dispatch, abort handling) as a prerequisite.","Check the ESR in a temporary debug handler to find what invoked the vector if the origin is unclear."],"exampleFix":"// before\nunsafe { core::arch::asm!(\"msr SPSel, #0\"); } // switches to SP_EL0 -> unsupported\n// after\n// keep SPSel = 1: kernel always uses SP_ELx at EL1\nunsafe { core::arch::asm!(\"msr SPSel, #1\"); }","handlingStrategy":"validation","validationCode":"// Assert the kernel never switches to SP_EL0:\nfn ensure_kernel_sp() {\n    let spsel: u64;\n    unsafe { core::arch::asm!(\"mrs {}, SPSel\", out(reg) spsel) };\n    assert!(spsel == 1, \"SPSel must be 1 at EL1\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never run code at EL0 or switch SPSel to 0 in this kernel.","Mask exceptions (DAIF) around any stack-pointer manipulation.","Do not issue SVC/syscall instructions unless EL0 support is implemented.","Verify VBAR_EL1 routing so exceptions land on supported entries."],"tags":["aarch64","bare-metal","el0","panic","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"644474cc09f755249f9c55d99a5d1e07a2562fc7","analyzedAt":"2026-09-06T09:25:56.584Z","contentChangedAt":"2026-09-06T09:25:56.584Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}